Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How am I able to make multiple waypoints/paths for my NPC to walk to?

Asked by 4 years ago
Edited 4 years ago

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.

0
What's wrong with your current code? Nowaha 459 — 4y
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. beeswithstingerss 41 — 4y

Answer this question