Pathfinding refuses to climb top of ladder

My pathfinding NPC is able to successfully path to a truss, but becomes immobile once it reaches a position close to the top. I’m not sure why is stops moving here - any ideas? Attached is an image of the issue and the script I am using to pathfind.
image

The script:

local Pathfind = game:GetService("PathfindingService")


local module = {}

function module.PathfindToLocation(char, goal: Vector3)
	local hum: Humanoid = char:WaitForChild("Humanoid")
	local blocked
	local done 
	local doneConnect
	local nextWaypoint = 0
	
	local path: Path = Pathfind:CreatePath({
		AgentCanJump = true,
		AgentCanClimb = true
	})
	
	local success, errorMessage = pcall(function()
		path:ComputeAsync(char.PrimaryPart.Position, goal)
	end)
	
	if success and path.Status == Enum.PathStatus.Success then
		local waypoints: {PathWaypoint} = path:GetWaypoints()
		
		blocked = path.Blocked:Connect(function(blockedWaypointIdx)
			print("Path blockd")
			if blockedWaypointIdx > nextWaypoint then
				module.PathfindToLocation(char, goal)
				doneConnect:Disconnect()
				blocked:Disconnect()
			end
		end)
		
		if not doneConnect then
			doneConnect = hum.MoveToFinished:Connect(function(reached)
				if reached and nextWaypoint < #waypoints then
					nextWaypoint += 1
					hum:MoveTo(waypoints[nextWaypoint].Position)
					if waypoints[nextWaypoint].Action == Enum.PathWaypointAction.Jump and not (hum:GetState() == Enum.HumanoidStateType.Climbing) then
						hum.Jump = true
					end
					
				else
					doneConnect:Disconnect()
					blocked:Disconnect()
				end
			end) 
		end
		
		nextWaypoint = 2
		hum:MoveTo(waypoints[nextWaypoint].Position)
	else
		print(errorMessage)
	end
end

return module

2 Likes

pathfind does not include ladders
pathfinding with ladders.rbxl (43.6 KB)

2 Likes

Thanks for your response, but my issue is with trusses, not custom ladders. The documentation explicitly states that it is compatible with trusses, and my pathfinding is successfully getting onto the truss, but no further. The script you sent doesn’t even work with trusses.

2 Likes

Can you add a DangerZone pathfinding modifier to the building ledge and set DangerZone= math.huge in your path?

2 Likes