System Information:
Windows 11 Pro 24H2
this is the code used in the issue:
function AI:MoveToPlace(character :Model,place)
if not place or not workspace.Targets:FindFirstChild(place) then
warn("Invalid arguments sent to AI")
return
end
local humanoid = character:FindFirstChildOfClass("Humanoid")
local root = character:FindFirstChild("HumanoidRootPart")
-- Create waypoints
local waypoints = PatchFindingService:CreatePath(
{
AgentRadius = 3,
AgentHeight = 6,
AgentCanJump = false,
})
local sucess,errorm = pcall(function()
waypoints:ComputeAsync(root.Position, workspace.Targets[place].Position)
end)
if sucess and waypoints.Status == Enum.PathStatus.Success then
AIState = "Moving"
for i,waypoint in pairs(waypoints:GetWaypoints()) do
if waypoint.Action == Enum.PathWaypointAction.Jump then
humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
end
--if waypoints.Unblocked then
-- humanoid:MoveTo(workspace.Targets[place].Position + Vector3.new(0,3.2,0))
-- break
--end
humanoid:MoveTo(waypoint.Position)
humanoid.MoveToFinished:Wait()
end
root.CFrame = workspace.Targets[place].CFrame + Vector3.new(0,3.2,0)
else
warn(errorm)
end
end
You are mistaken in your code. PathfindingService
will never throw errors under normal circumstances, so sucess
will always be true
, even when waypoints.Status
is not Enum.PathStatus.Success
. This also means that errorm
is always nil
, as no error will ever occur.
Ok, yes, I do know one error that can occur, however it usually only happens when your NPC has fallen out of the world or has been flung, and moved several thousands of studs away from the pathfinding goal. This shouldn’t be anything to worry about normally and, if it occurs, the NPC is probably unable to reach the goal anyway so there’s no failsafe other than despawning it.
Hello MagicLuau,
Thank you for reporting this issue. Judgy_Oreo is correct in pointing out that PathfindingService:ComputeAsync
rarely throws Lua errors that would be caught by pcall
. Therefore, the errorm
variable will likely always be nil
, even when waypoints.Status
is not Enum.PathStatus.Success
.
Based on the information provided and the fact that your warn(errorm)
is outputting “nil”, it’s highly probable that the waypoints.Status
is Enum.PathStatus.NoPath
. This means the pathfinding service was unable to find a valid path between the root.Position
and workspace.Targets[place].Position
.
If you believe that PathfindingService should be returning a path in this scenario, despite the NoPath
status, please provide us with a minimal reproduction place file and the following information so we can investigate further:
-
Pathfinding Parameters: The exact parameters you are passing to
PatchFindingService:CreatePath
(in this case:AgentRadius = 3
,AgentHeight = 6
,AgentCanJump = false
). -
StartPosition: The
root.Position
of the character whenComputeAsync
is called. -
EndPosition: The
workspace.Targets[place].Position
of the target. - Expected Result: What kind of path were you expecting the PathfindingService to generate?
-
Actual Result: That
waypoints.Status
isEnum.PathStatus.NoPath
andwaypoints:GetWaypoints()
returns an empty table.
With this information, we can better understand the context and attempt to reproduce the issue on our end.
Thank you for your cooperation.