Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local get_path = require( game.ServerScriptService:WaitForChild("A*") )
- local fig = script.Parent
- local torso = fig.WaitForChild("HumanoidRootPart")
- local humanoid = fig.WaitForChild("Humanoid")
- function follow_path(goal)
- if not goal then return end
- local from = torso.Position
- local to = goal.Position
- local path = get_path(from, to)
- for _,node in ipairs(path or {})do
- repeat wait()
- humanoid:MoveTo(node)
- until (node - torso.Position).Magnitude <= 4
- end
- end
- function get_closest_player(to)
- local dist = math.huge
- local output = nil
- for _,user in ipairs(game.Players:GetPlayers())do
- local diff = user:DistanceFromCharacter(to)
- if diff < dist and user.Character then
- dist = diff
- output = user.Character
- end
- end
- return output
- end
- while wait() do
- local user = get_closest_player(torso.Position)
- local root = user and user:FindFirstChild("HumanoidRootPart")
- follow_path(root)
- end
Advertisement
Add Comment
Please, Sign In to add comment