Advertisement
Hasli4

RBLX. DemonFindPath

May 12th, 2025
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.24 KB | None | 0 0
  1. local PathfindingService = game:GetService("PathfindingService")
  2. local Debris = game:GetService("Debris")
  3. local Demon = script.Parent.DemonType
  4. while true do
  5.     local destination = game.Workspace.Data.Player.Value
  6.     local distance = (Demon.RootPart.Position - destination.Character.HumanoidRootPart.Position).magnitude
  7.     if distance < 50 then
  8.         Demon.WalkSpeed = script.Parent.Parent.WalkSpeed.Value
  9.        
  10.         local path = PathfindingService:CreatePath({
  11.             AgentRadius = 2;
  12.             AgentHeight = 5;
  13.             AgentCanJump = false;       })
  14.         path:ComputeAsync(Demon.RootPart.Position, destination.Character.HumanoidRootPart.Position)
  15.         waypoints = {}
  16.         if path.Status == Enum.PathStatus.Success then
  17.             waypoints = path:GetWaypoints()
  18.             currentWaypointIndex = 1
  19.             for _, waypoint in pairs(waypoints) do
  20. Demon:MoveTo(waypoints[currentWaypointIndex].Position)
  21.                 Demon.MoveToFinished:Wait()
  22.                 currentWaypointIndex += 1
  23.                 if waypoints[currentWaypointIndex] == nil then
  24.                     break
  25.                 end
  26.             end
  27.  
  28. else        Demon:MoveTo(game.Workspace.Spawners.Spawner.SpawnPoint.Position+Vector3.new(math.random(10), 0, math.random(10)))
  29.             Demon.MoveToFinished:Wait()
  30.         end
  31.     else
  32.         Demon:MoveTo(game.Workspace.Spawners.Spawner.SpawnPoint.Position)
  33.     end
  34.     wait(0.1)
  35. end
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement