local players = game:GetService("Players"):GetChildren() local target local nearest = {} local movemessage = "The parent humaniod has tried to move, but unfortunately might've failed." while wait() do for i = 1,#players do local distance = (script.Parent.Torso.Position-players[i].Character.Torso.Position).magnitude if distance <= 20 then table.insert(nearest,1,players[i].Character.Torso.Position) table.sort(nearest,#nearest) target = nearest[1] else return end end end local debounce = false while wait(2) do walktoplayer() end function walktoplayer() if target ~= nil and debounce == false then debounce = true local path = game:GetService("PathfindingService"):FindPathAsync(script.Parent.Torso, target) local points = path:GetWaypoints() for i,v in pairs(points) do local stud = Instance.new("Part", workspace) stud.Anchored = true stud.CanCollide = false stud.CFrame = CFrame.new(v.Position) stud.Size = Vector3.new(1,1,1) end if path.Status == Enum.PathStatus.Success then for i,v in pairs(points) do script.Parent.Humanoid:MoveTo(v.Position) print(movemessage) script.Parent.Humanoid.MoveToFinished:Wait() if v.Action == Enum.PathWaypointAction.Jump then script.Parent.Humanoid.Jump = true end end end debounce = false end end
Doesn't even print the movemessage. What's the issue?
local players = game:GetService("Players"):GetChildren() local target local nearest = {} local movemessage = "The parent humaniod has tried to move, but unfortunately might've failed." while wait() do for i = 1,#players do local distance = (script.Parent.Torso.Position-players[i].Character.Torso.Position).magnitude if distance <= 20 then table.insert(nearest,1,players[i].Character.Torso.Position) table.sort(nearest,#nearest) target = nearest[1] else return end end end local debounce = false while wait(2) do walktoplayer() end function walktoplayer() if target ~= nil and debounce == false then debounce = true local path = game:GetService("PathfindingService"):FindPathAsync(script.Parent.Torso, target) local points = path:GetWaypoints() local ExistedPoints = {} local index= 0 for i,v in pairs(points) do local stud = Instance.new("Part", workspace) stud.Name = "Waypoint[" .. i .. "]" stud.Anchored = true stud.CanCollide = false stud.CFrame = CFrame.new(v.Position) stud.Size = Vector3.new(1,1,1) index = index + 1 ExistedPoints[index] = stud end if path.Status == Enum.PathStatus.Success then for i,v in pairs(ExistedPoints) do script.Parent.Humanoid:MoveTo(v.Position) print(movemessage) script.Parent.Humanoid.MoveToFinished:Wait() if points[i].Action == Enum.PathWaypointAction.Jump then script.Parent.Humanoid.Jump = true end end end debounce = false end end
The points are not real, make them real and establish a table for them.