Advertisement
SxScripting

Following Script

Oct 12th, 2020
316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.74 KB | None | 0 0
  1. local Humanoid = script.Parent.Humanoid
  2. local PrimaryPart = script.Parent.PrimaryPart
  3.  
  4. local FollowDistance = 15
  5.  
  6. function GetNearestPlayer()
  7.     local Pos, Distance = nil,math.huge
  8.     for i,v in pairs(game.Players:GetPlayers()) do
  9.         if not v or not v.Character or not v.Character.PrimaryPart then continue end
  10.         local DistanceFromCharacter = (PrimaryPart.Position-v.Character.PrimaryPart.Position).magnitude
  11.         if DistanceFromCharacter <= FollowDistance and DistanceFromCharacter < Distance then
  12.             Pos = v.Character.PrimaryPart.Position
  13.         end
  14.     end
  15.     return Pos
  16. end
  17.  
  18. while wait() do
  19.     local Pos = GetNearestPlayer()
  20.     local DP = game.Workspace.Dummypoint.Position
  21.     if Pos then
  22.         Humanoid:MoveTo(Pos)
  23.     else
  24.         Humanoid:MoveTo(DP)
  25.     end
  26. end
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement