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

Why does this pathfinding script not work?

Asked by 6 years ago
Edited 6 years ago
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...

0
I thought coord was already a table value. Are there any errors? CootKitty 311 — 6y

2 answers

Log in to vote
0
Answered by
Mayk728 855 Moderation Voter
6 years ago
Edited 6 years ago

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
Ad
Log in to vote
-2
Answered by 6 years ago

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.

0
Uhh... do you know what a for i,v loop is? I am using a loop. Void_Frost 571 — 6y

Answer this question