Pathfinding gets stuck in walls when following player

What I’m trying to do is literally just get the NPC to follow the player when they trigger the prompt inside of her. The issue is that she gets stuck on walls even with pathfinding, I’ve tried searching agentradius and height.

local NPC = script.Parent
local pathfinding_service = game:GetService("PathfindingService")

function getClosestPlayer()
	local closest_player, closest_distance = nil, 200
	for i, player in pairs(workspace:GetChildren()) do
		if player:FindFirstChild("Humanoid") and player ~= NPC then
			local distance = (NPC.PrimaryPart.Position - player.PrimaryPart.Position).Magnitude
			if distance < closest_distance then
				closest_player = player
				closest_distance = distance
	return closest_player, closest_distance

while true do
	local path = pathfinding_service:CreatePath()
	local player, distance = getClosestPlayer()
	if player and distance > 10 then
		path:ComputeAsync(NPC.HumanoidRootPart.Position, player.PrimaryPart.Position)
		local waypoints = path:GetWaypoints()
		for _, waypoint in pairs(waypoints) do  
			while true do
				local distance = (NPC.PrimaryPart.Position - waypoint.Position).Magnitude
				local distance_from_player = (NPC.PrimaryPart.Position - player.PrimaryPart.Position).Magnitude
				if distance < 5 then
				if distance_from_player < 10 then

I’m also trying to get it to move back to its original spot whenever the player dies/tells them to stop following them, but again, pathfinding doesn’t want to detect the walls or anything at all, and it gets stuck on the smallest things in Studio!

External Media

You need to add agent prams or what i will call it , pathfinding prams

pathfinding prams is use to set a rig’s size ,height , ability and preference/cost(quite hard to explain)


local agentParams = {

AgentRadius = 2.0,

AgentHeight = 5.0,

AgentCanJump = false,


some links that are helpful:

pathfinding cost:

if this is what you need, please mark it as solution <3


I just said that I tried params but that didn’t really work at all… she keeps trying to walk through walls

1 Like

did u try debugging like adding a part to the way point position? or you can try reducing the distance factor when comparing? I recommend a humanoid event that fires when the rig move to the target position. u can use a repeat loop until it reach the destination so u can still check the distance

I’m extremely new to pathfinding, and I have no idea how to do that, especially with events… :slightly_frowning_face: :sob: I’m not trying to ask for more help than what I’m already getting right now… I’m not sure if it’s having the issue because of the walls being too thin, or because of the doors or something?

you should try copying a youtuber script first like dev king . he use move to finish event but his scirpt does not lock onto the character . learn how to use pathfinder then move on to more advance pathfinding ai

Not sure if you seen this yet.

Been there and done that, his video is pretty outdated too it helped with my pathfinding learning but not with the issue.

Seen that, and read through it all yet nothing there helped at all, Pathfinding just sucks it can’t even detected a simple wall :sob:

how are the walls made? i cant recreat the issue, the npc follows me just fine.

The walls are made normally like it’s just thin walls nothing much

Can you add a PathfindingModifier to the door model and enable the PassThrough?

Sure I’ll try to do that and I’ll update on if it works or not