Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Humanoid = script.Parent.Humanoid
- local PrimaryPart = script.Parent.PrimaryPart
- local FollowDistance = 15
- function GetNearestPlayer()
- local Pos, Distance = nil,math.huge
- for i,v in pairs(game.Players:GetPlayers()) do
- if not v or not v.Character or not v.Character.PrimaryPart then continue end
- local DistanceFromCharacter = (PrimaryPart.Position-v.Character.PrimaryPart.Position).magnitude
- if DistanceFromCharacter <= FollowDistance and DistanceFromCharacter < Distance then
- Pos = v.Character.PrimaryPart.Position
- end
- end
- return Pos
- end
- while wait() do
- local Pos = GetNearestPlayer()
- local DP = game.Workspace.Dummypoint.Position
- if Pos then
- Humanoid:MoveTo(Pos)
- else
- Humanoid:MoveTo(DP)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement