Advertisement
TheRealAaron

I added a pcal function

Jan 5th, 2025
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. local ServerStorage = game:GetService("ServerStorage")
  2. local Enemy = {}
  3.  
  4. function Enemy.Move(enemy, map)
  5. local humanoid = enemy:WaitForChild("Humanoid")
  6. local waypoints = map.Waypoints
  7.  
  8. for waypoint = 1, #waypoints:GetChildren() do
  9. local target = waypoints:GetChildren()[waypoint]
  10. humanoid:MoveTo(target.Position)
  11. humanoid.MoveToFinished:Wait()
  12. end
  13. end
  14.  
  15. function Enemy.Spawn(name, map)
  16. local enemyTemplate = ServerStorage.Enemies:FindFirstChild(name)
  17.  
  18. if enemyTemplate then
  19. local newEnemy = enemyTemplate:Clone()
  20. newEnemy.HumanoidRootPart.CFrame = map.Start.CFrame
  21. newEnemy.Parent = workspace
  22.  
  23. local success, errorMessage = pcall(function()
  24. Enemy.Move(newEnemy, map)
  25. end)
  26.  
  27. if not success then
  28. warn("Error moving enemy: " .. errorMessage)
  29. end
  30. else
  31. warn("Enemy not found: " .. name)
  32. end
  33. end
  34.  
  35. return Enemy
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement