Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local player = game.Players.LocalPlayer
- local character = player.Character or player.CharacterAdded:Wait()
- local localroot = character:WaitForChild("HumanoidRootPart")
- local humanoid = character:WaitForChild("Humanoid")
- local PS = game:GetService("PathfindingService")
- local path = PS:CreatePath({
- AgentRadius = 2,
- AgentJumpHeight = 10,
- AgentMaxSlope = 10,
- AgentCanJump = true,
- AgentCanClimb = true
- })
- local function closest()
- local range = math.huge
- local target = nil
- for _, v in pairs(game.Players:GetPlayers()) do
- if v ~= player and v.Character then
- local JN = v.Character:FindFirstChild("HumanoidRootPart")
- if JN then
- local dist = (localroot.Position - JN.Position).magnitude
- if dist < range then
- range = dist
- target = v
- end
- end
- end
- end
- return target
- end
- local function Goto(target)
- if target and target.Character then
- local th = target.Character:FindFirstChild("HumanoidRootPart")
- if th then
- path:ComputeAsync(localroot.Position, th.Position)
- local waypoints = path:GetWaypoints()
- for _, v in pairs(waypoints) do
- humanoid:MoveTo(v.Position)
- humanoid.MoveToFinished:Wait()
- if v.Action == Enum.PathWaypointAction.Jump then
- humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
- end
- end
- end
- end
- end
- local target = closest()
- Goto(target)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement