So this works fine, the only problem I'm having is that the NPC has to finish 100% before going to a new point. This is a pretty big issue.
So my question is how can I stop MoveToFinished before it's finished, is there a way to cancel it out and start over if the player has moved positions and there is a new endpoint?
There aren't too many examples on the new PathfindingService and this is the first time I've used it.
local PathfindingService = game:GetService("PathfindingService")
function find(pos)
local dis = 10000
local tor = nil
for i,v in pairs(game.Players:GetPlayers()) do
if v.Character then
if v.Character:FindFirstChild("HumanoidRootPart") and v.Character:FindFirstChild("Humanoid") then
local hrp,hum = v.Character.HumanoidRootPart,v.Character.Humanoid
if hum.Health > 0 then
if (hrp.Position - pos).magnitude < dis then
tor = hrp
dis = (hrp.Position - pos).magnitude
end
end
end
end
end
return tor
end
while wait(.25) do
local target = find(script.Parent.HumanoidRootPart.Position)
if target ~= nil then
local path = PathfindingService:FindPathAsync(script.Parent.HumanoidRootPart.Position, target.Position)
local waypoints = path:GetWaypoints()
for currentPoint = 1, #waypoints do
local waypoint = waypoints[currentPoint]
script.Parent.Humanoid:MoveTo(waypoint.Position)
if waypoint.Action == Enum.PathWaypointAction.Jump then
script.Parent.Humanoid.Jump = true
end
script.Parent.Humanoid.MoveToFinished:Wait()
end
end
end

2 comments
script.Parent.Humanoid:MoveTo(script.Parent.Position) should stop the humanoid (you many need to inc an offset) and fire MoveToFinished
i coulda sworn you could just add break and itll stop the code from running.