PathfindingService: path request is too long

I am making mobs in my game. The mobs find the closest player, and chase them. However, when I do
path:ComputeAsync(torso,part) to find the path, it sometimes prints the error PathfindingService: path request is too long.

While I could make a magnitude check between the player’s torso and the mob, it would not be very accurate, as magnitude does not directly equate to pathfinding length. How else could I check if the magnitude check is too long before computing the async?

When using PathfindingService, you create waypoints or use pcall to prevent this error.

Example of what you could do:

local Success, ErrorMessage = pcall(function()
		
		Path:ComputeAsync(Subject.HumanoidRootPart.Position, Destination)
		
	end)
	if Success and Path.Status == Enum.PathStatus.Success then
		WayPoints = Path:GetWaypoints()

		Blocked_Connection = Path.Blocked:Connect(function(Blocked_WayPoint_Index)
			if Blocked_WayPoint_Index > Next_Waypoint_Index then
				Blocked_Connection:Disconnect()
				FollowPath(Destination)
			end

		end)

You usually use this to set paths close enough foe the NPC to reach it, it technically doesnt follow the player anymore, just the waypoints.

4 Likes

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