Pathfinding Acting Weird

You can write your topic however you want, but you need to answer these questions:

  1. I am trying to make a Citizen NPC using Pathfinding Service.

  2. The problem is that the the path is calculated correctly and the NPC tried to avoid the wall, but right at the end the calculations goes a little off and makes the NPC slam into the wall. https://gyazo.com/4db964fbe3fdac8eb1d93555c2b3c55d
    As you can see in the video, the NPC tries to avoid the wall but misses it just by a few studs.

  3. I have tried to find a solution across discord servers and the Forum but was unable to find one.

local Citizen = script.Parent
local PathFront2 = game.Workspace.PathFront2
local PathBack1 = game.Workspace.PathBack1
local Humanoid = Citizen.Humanoid
local Torso = script.Parent:FindFirstChild("UpperTorso")
local PathFindingService = game:GetService("PathfindingService")

local PathFront = PathFindingService:CreatePath()
local PathBack = PathFindingService:CreatePath()
local waypoints1
local waypoints2

function onGo()
	--before while loop
	PathFront.Blocked:Connect(function()
		print("Break!")
		breakPath = true
	end)

	--in while loop
	PathFront:ComputeAsync(Torso.Position, PathFront2.Position)
	if PathFront.Status == Enum.PathStatus.Success then
		breakPath = false

		waypoints1 = PathFront:GetWaypoints()
		local wastedTime = 0
		for _, waypoint in ipairs(waypoints1) do	
			repeat
				wastedTime = wastedTime + 1
				if(waypoint.Action == Enum.PathWaypointAction.Jump) then
					Humanoid.Jump = true
				end

				if breakPath == true then break end
				Humanoid:MoveTo(waypoint.Position)
				wait()
			until (Torso.Position - waypoint.Position).magnitude < 8 or breakPath == true or wastedTime >= 50
		end
	end
end```

Maybe try to recalculate? Or redirect the NPC a bit earlier?

I don’t think that’s the problem here.

Try raycasting to check if there is an object in front of the NPC or make your own pathfinding module like an A* instead of using Roblox’s service since it isn’t usually reliable.

You should try adjusting some of the pathfinding’s params.

Which you can read about here:

If that still doesn’t work, go for a visual debugging approach. Plot a part down at each waypoint of the path and see if it’s actually the service having trouble.

I have solved this problem by setting the ServerNetworkOwner of the NPC to nil. Thanks for all your help!