My pathfinding script currently only lets my NPC walk to 1 waypoint. How do I make it walk to other waypoints?

-- script
local playertorso = script.Parent.Torso.Position
local location = workspace.location.Position
local npc = script.Parent.Humanoid

local path = game:GetService("PathfindingService"):FindPathAsync(playertorso,location)
local points = path:GetWaypoints()

if path.Status == Enum.PathStatus.Success then
 for i,v in pairs(points) do
  npc:MoveTo(v.Position)
  npc.MoveToFinished:Wait()
  if v.Action == Enum.PathWaypointAction.Jump then
   npc.Jump = true
  end
 end
end
 

Help will be appreciated, thanks.

2 comments

0

What's wrong with your current code?

0

The code that's running actually walks to multiple waypoints. In the way you are using  the for loop, the npc will walk to a point, wait till it has arrived, then walk to the next, making it seem like there is only one point: The destination. Now if you mean multiple at the same time, you can't as this will just confuse the game.