Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why does this pathfinding script not work?

local pathservice = game:GetService("PathfindingService")
local path= pathservice:FindPathAsync(game.Workspace.Start.Position,game.Workspace.End.Position,512)
local coord=path:GetWaypoints()
wait()
for i,v in pairs(coord) do
wait()
print ("executing "..i,v)
game.Workspace.Robot.Humanoid:MoveTo(v)
print("Moving to: ",v)
game.Workspace.Robot.Humanoid.MoveToFinished:wait()
end


Seems good to me...

1 comment

0

I thought coord was already a table value. Are there any errors?

2 answers

✓ Accepted answer

Simple mistake. All you have to do is add .Position next to v, because v is an Instance created part and you didn't tell the script to move to the position, just the part itself. That's what caused an error.

Fixed:

local pathservice = game:GetService("PathfindingService")
local path= pathservice:FindPathAsync(game.Workspace.Start.Position,game.Workspace.End.Position,512)
local coord = path:GetWaypoints()
wait()
for i,v in pairs(coord) do
	wait()
	print ("executing "..i,v)
	game.Workspace.Robot.Humanoid:MoveTo(v.Position)
	print("Moving to: ",v)
	game.Workspace.Robot.Humanoid.MoveToFinished:wait()
end

You need to loop through the table constantly to continue updating the values and constantly moving to the next point in the table

Use a for loop for this.

1 comment

0

Uhh... do you know what a for i,v loop is? I am using a loop.

This discussion is preserved as it was. New answers, comments, and votes are closed.