Pathfinding almost always fails?

Context

So basically I am making a script that spawns NPC’s and moves them into a house using PathFindingService.
Only problem is, it always fails to pathfind.

I’ve have asked in multiple places and just cant seem to figure it out.

Questions others have asked

  • Is the NPC unanchored? Yes
  • Is it moving the right NPC? Yes I have gone and tested it. It is moving the right NPC.
  • Errors? I does not print any errors. But I have made it so it prints the pathfinds Status. Which always returns as NoPath.

Code

-- events
local events = game:GetService('ReplicatedStorage'):FindFirstChild('NPCs events')

local setupBomb = events:FindFirstChild('SetupBomb')

-- entries
local entriePoints = workspace:FindFirstChild('Entrances')

local EPNumber = #entriePoints:GetChildren()

-- services
local pathFindingService = game:GetService('PathfindingService')

local attempts = 20



local function sendToPlace(npc,endPoint)
	print(npc.Name)
	warn('Pathfinding!')
	local hum = npc:FindFirstChild('Humanoid')
	
	local path:Path
	
	for attempt = 1, attempts, 1 do
		path = pathFindingService:CreatePath()
		
		if path.Status == Enum.PathStatus.Success then
			path:ComputeAsync(npc.PrimaryPart.Position,endPoint.Position)
			local waypoints = path:GetWaypoints()

			

			-- use the waypoints
			for i, waypoint in pairs(waypoints) do
				if waypoint.Action == Enum.PathWaypointAction.Jump then
					hum.Jump = true
				end
				hum:MoveTo(waypoint.Position)
				hum.MoveToFinished:Wait(2)
			end
			attempt = attempts
		else
			warn('Failed to pathfind!')
			warn(path.Status)
		end
		task.wait(1)
	end
	
end




local function enter(npc) -- make an NPC enter the building!
	print('Making '..npc.Name..' enter the place!')
	
	local entryPoint = entriePoints:GetChildren()[math.random(1,EPNumber)]
	print('Entering at '..entryPoint.Name)
	
	task.spawn(sendToPlace,npc,entryPoint)
end





setupBomb.Event:Connect(function(NPC) -- yes this does fire and run. It does it three times
	wait(3)
	task.spawn(enter,NPC)
end)
  • So why is this happening?
  • How can I fix it?
  • Or is there another solution?

All help is appreciated!

~Froyo~

That might be the issue, I have seen there are a lot of issues with pathfinding and indoor areas.

More ideas and questions:

  1. Have you checked the navmesh to see if a possible path is generated?
  2. Have you tried adjusting the agent radius?

Example Pathfinding testing from @koziahss:

Well right now it doesnt put them in the house yet.
Right now it just makes them walk up to the door.

I moved the door away from the house it still doesnt work

Question. Can a path find only run if it is in a certain distance?