Advertisement
SigmaBoy456

Path to player #8472 example

Aug 30th, 2024
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. local player = game.Players.LocalPlayer
  2. local character = player.Character or player.CharacterAdded:Wait()
  3. local localroot = character:WaitForChild("HumanoidRootPart")
  4. local humanoid = character:WaitForChild("Humanoid")
  5. local PS = game:GetService("PathfindingService")
  6. local path = PS:CreatePath({
  7. AgentRadius = 2,
  8. AgentJumpHeight = 10,
  9. AgentMaxSlope = 10,
  10. AgentCanJump = true,
  11. AgentCanClimb = true
  12. })
  13. local function closest()
  14. local range = math.huge
  15. local target = nil
  16. for _, v in pairs(game.Players:GetPlayers()) do
  17. if v ~= player and v.Character then
  18. local JN = v.Character:FindFirstChild("HumanoidRootPart")
  19. if JN then
  20. local dist = (localroot.Position - JN.Position).magnitude
  21. if dist < range then
  22. range = dist
  23. target = v
  24. end
  25. end
  26. end
  27. end
  28. return target
  29. end
  30. local function Goto(target)
  31. if target and target.Character then
  32. local th = target.Character:FindFirstChild("HumanoidRootPart")
  33. if th then
  34. path:ComputeAsync(localroot.Position, th.Position)
  35. local waypoints = path:GetWaypoints()
  36. for _, v in pairs(waypoints) do
  37. humanoid:MoveTo(v.Position)
  38. humanoid.MoveToFinished:Wait()
  39. if v.Action == Enum.PathWaypointAction.Jump then
  40. humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
  41. end
  42. end
  43. end
  44. end
  45. end
  46. local target = closest()
  47. Goto(target)
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement