local PATH = game:GetService('PathfindingService')
local boat = game.Workspace.MAP.RELATED_TO_BOAT.Boat
local start = game.Workspace.MAP.RELATED_TO_BOAT.FOLDER_PATH.Start
local finish = game.Workspace.MAP.RELATED_TO_BOAT.FOLDER_PATH.Finish_Road
local createPath = PATH:CreatePath()
createPath:ComputeAsync(start.Position, finish.Position)
local waypoints = createPath:GetWaypoints()
for _, waypoint in pairs(waypoints) do
print(waypoint.Position)
end
I also tries with pcall function, but nothing work again
Are you sure that the parts your trying to use have been created? Also try printing out the path status
By doing print(createpath.Status) after compute async
If the script is a LocalScript and is inside of an NPC that’s in Workspace, it will not work, since LocalScripts are unable to run when descendants of Workspace (with the exception of player characters). To fix this problem, replace the LocalScript with a server Script and make sure to set its RunContext to Client in the Properties tab. A server Script with its RunContext set to Client will run client-sided as a LocalScript would, and is able to run inside of Workspace
I did the code in the server script, maybe it’s because the instance i want to move is a model ? But it doesn’t make sense, because the issue is ComputeAsync doesn’t show up ? And i didn’t make a code for the model to move.
ComputeAsync is able to fail, and if so, would explain the issues you’re experiencing. I’ll write how to detect when it does and edit this comment with the code
Here’s the code:
local PathfindingService = game:GetService("PathfindingService")
local Workspace = game:GetService("Workspace")
local folder = Workspace.MAP.RELATED_TO_BOAT.FOLDER_PATH
local start = folder.Start
local finish = folder.Finish_Road
local path = PathfindingService:CreatePath()
local success, error = pcall(path.ComputeAsync, path, start, finish) -- pcall will catch any errors that might occur
if success and path.Status == Enum.PathStatus.Success then
for _, waypoint in path:GetWaypoints() do
print(waypoint.Position, waypoint.Action)
end
else
warn(`Path compute failed.\nError: {error}\nPath Status: {path.Status}`)
end
I’m using pcall to catch any errors that might occur if ComputeAsync fails, and checking if the path’s status is Success before iterating over the waypoints
@Evisneff I checked with the Assistant to see what can cause a Path’s status to be NoPath, and it did mention something that is quite useful: If either the start position or the finish position happens to be inside of a solid object (so as an example, an Attachment that’s in the center of a Part), it can cause the path to fail, so do be sure to check if that’s the case
Hi, thank you for your help, but there is this error :
Path compute failed.
Error: Unable to cast Instance to Vector3
Path Status: Enum.PathStatus.NoPath
Also, i my start and end points are parts. Nothing inside
That means that either the value of the start variable or the finish variable isn’t a Vector3 value, so if Start and Finish_Road are BaseParts, this will fix the problem:
local PathfindingService = game:GetService("PathfindingService")
local Workspace = game:GetService("Workspace")
local folder = Workspace.MAP.RELATED_TO_BOAT.FOLDER_PATH
local start = folder.Start.Position
local finish = folder.Finish_Road.Position
local path = PathfindingService:CreatePath()
local success, error = pcall(path.ComputeAsync, path, start, finish) -- pcall will catch any errors that might occur
if success and path.Status == Enum.PathStatus.Success then
for _, waypoint in path:GetWaypoints() do
print(waypoint.Position, waypoint.Action)
end
else
warn(`Path compute failed.\nError: {error}\nPath Status: {path.Status}`)
end
@Evisneff Another test you can do is try to move the end point somewhere where there’s a ground the NPC can easily walk on, since from the perspective of the screenshot, the end point seems to be floating above the void, which might be causing the path to fail if the NPC is unable to reach that position by walking or jumping
It works ! I think my start point was very far from the end point, i also resized the start point to vector(1,1,1) like the end point and it return something. Thank you !