I’ve been trying to make a client system using pathfinding but there has been times where the pathfinding doesn’t find a path when there’s clearly one, despite multiple attempts as seen in these pictures below.

code:
local initpos = Positions.Shop.Position+NumberUtility.DeserializeVector3(clientData.position)
local finalpos = Positions.Shop.Position+GetDestinationBasedOnStep(clientData)
local walkspeed = clientData.walkspeed
local timeRequired = (finalpos-initpos).Magnitude/walkspeed
local y = (Positions.Shop.Position.Y-Positions.Shop.Size.Y/2) + newModel:GetExtentsSize().Y/2
if clientData.time/timeRequired>=1 then
print("skipped ".. clientData.step)
return
end
local pathfinding = PathfindingService:CreatePath({
AgentRadius = 2,
AgentHeight = 2,
AgentCanJump = false,
AgentCanClimb = false,
WaypointSpacing = (finalpos-initpos).Magnitude/10,
Costs = {
Plastic = 0.01,
Door = 0.01,
DangerZone = math.huge,
}
})
initpos = Vector3.new(initpos.X, y, initpos.Z)
finalpos = Vector3.new(finalpos.X, y, finalpos.Z)
pathfinding:ComputeAsync(initpos, finalpos)
local waypoints = pathfinding:GetWaypoints()
if not waypoints or not waypoints[1] then
print("no waypoints for ".. clientData.step)
return task.delay(.5, CreateNewBezier, clientData, newModel)
end
local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Include
params.FilterDescendantsInstances = {workspace.Map}
print("waypoint completed for ".. clientData.step)
local points = {}
local interval = #waypoints/20
local raycast = workspace:Raycast(waypoints[1].Position, -Vector3.new(0, 100, 0), params)
local groundDistance = raycast and raycast.Distance or 0
local offset = Vector3.new(0, -groundDistance+newModel:GetExtentsSize().Y/2, 0)
local startpos = waypoints[1].Position+offset
table.insert(points, startpos)
for index, v in (waypoints) do
if index == 1 then
continue
end
if index%interval == 0 and index ~= #waypoints then
continue
end
table.insert(points, v.Position+offset)
end
ClientsBeziers[clientData.uid] = BezierCurve.new(table.unpack(points))
return true
I would like to know what could result in this behavior and how to solve it in order to have a functional system.