ComputeAsync() doesn't work and doesn't show

Hi,
I just learn how to code path finding, as you can see in the title ComputerAsync doesn’t work.
In this image, ComputeAsync doesn’t show at all.

Also, I tried with this code, but nothing run.

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

1 Like

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

1 Like

Yes 100% sure :slight_smile:
And it says “Enum.PathStatus.NoPath”
The parts are in workspace. That’s why, i didn’t use “WaitForChild()”.

1 Like

Are you sure that the parts are on the same y axis, or can be gotten to if not. And their is nothing blocking them

1 Like

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 :slight_smile::+1:

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 :slight_smile::+1:


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

1 Like

I might be wrong, but I have never seen ComputeAsync pop up for me. It might just not show up.

2 Likes

That issue is happening because CreatePath’s return type is Instance rather than Path for some reason, even though the value it returns is a Path

Hi, thank you for your help, but there is this error :frowning: :
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 :slight_smile:

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

Unfortunatly, the same issue occurs :frowning:

Path compute failed.
Error: nil
Path Status: Enum.PathStatus.NoPath

I will tried to use others maybe with basepart it doesn’t work

And @Mighty1964 you’re right, in the youtube tutorial, ComputeAsync doesn’t show

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 !

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.