Advertisement
Guest User

Pathfinding

a guest
Apr 5th, 2020
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.15 KB | None | 0 0
  1. local PLR1010 = game.Players.LocalPlayer
  2. local Paths = game:GetService("PathfindingService")
  3.  
  4. local part = game:GetService("Workspace")["Elevators"]["Lobby"]["Floor"]
  5.  
  6. function WalkTo(Vec3,TimeOut,...)
  7.     local Options = {...}
  8.     local hum = PLR1010.Character:FindFirstChild("Humanoid")
  9.     local root = PLR1010.Character:FindFirstChild("HumanoidRootPart")
  10.     if hum and root then
  11.         on = true
  12.         if TimeOut > 0 then
  13.             coroutine.resume(coroutine.create(function()
  14.                 iter = 0
  15.                 repeat
  16.                     wait(.1)
  17.                     iter = iter + .1
  18.                 until not on or iter >= TimeOut
  19.                 on = false
  20.             end))
  21.         end
  22.         local path = Paths:CreatePath(Options[1] or 2,Options[2] or 5,Options[3] or true)
  23.         path:ComputeAsync(root.Position, Vec3)
  24.         print(path)
  25.         local waypoints = path:GetWaypoints()
  26.         if path.Status == Enum.PathStatus.Success then
  27.             for _,point in pairs(waypoints) do
  28.                 if not on then break end
  29.                 hum:MoveTo(point.Position)
  30.                 hum.MoveToFinished:Wait()
  31.             end
  32.             for Checks = 1,3 do
  33.                 if not on then break end
  34.                 hum:MoveTo(waypoints[#waypoints].Position)
  35.                 hum.MoveToFinished:Wait()
  36.             end
  37.         end
  38.         on = false
  39.     end
  40. end
  41.  
  42. WalkTo(part.Position,0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement