Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local ServerStorage = game:GetService("ServerStorage")
- local Enemy = {}
- function Enemy.Move(enemy, map)
- local humanoid = enemy:WaitForChild("Humanoid")
- local waypoints = map.Waypoints
- for waypoint = 1, #waypoints:GetChildren() do
- local target = waypoints:GetChildren()[waypoint]
- humanoid:MoveTo(target.Position)
- humanoid.MoveToFinished:Wait()
- end
- end
- function Enemy.Spawn(name, map)
- local enemyTemplate = ServerStorage.Enemies:FindFirstChild(name)
- if enemyTemplate then
- local newEnemy = enemyTemplate:Clone()
- newEnemy.HumanoidRootPart.CFrame = map.Start.CFrame
- newEnemy.Parent = workspace
- local success, errorMessage = pcall(function()
- Enemy.Move(newEnemy, map)
- end)
- if not success then
- warn("Error moving enemy: " .. errorMessage)
- end
- else
- warn("Enemy not found: " .. name)
- end
- end
- return Enemy
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement