Pathfinding doesn't occur

I try to make the npc (the virus character) follow the player, but the problem is the npc runs into walls when the player turns a corner. I’ve tried using Humanoid.MoveToFinished:Wait()
but it still doesn’t seem to work.

game.ReplicatedStorage.RoomNumber.Changed:Connect(function(new)
	if new == range1.Min + 1 then
		virus.HumanoidRootPart.Anchored = false
		spawn(function()
			while game.ReplicatedStorage.RoomNumber.Value < range1.Max do
	local path = game.PathfindingService:CreatePath(agentParams)
	local character = game.Players:FindFirstChildWhichIsA("Player").Character
	path:ComputeAsync(virus.PrimaryPart.Position, character.PrimaryPart.Position)
	--if path.Status == Enum.PathStatus.Success then
		local waypoints = path:GetWaypoints()
		
		for _, waypoint in pairs(waypoints) do
			virus.Humanoid:MoveTo(waypoint.Position)
		end
	--end
	task.wait()
	
end
		end)
		
	end
end)
1 Like

Are you sure you defined agentParams? if yes, just change agentradius.
You can measure the radius by placing a part and making its size same with your virus character

2 Likes

:Connect does something called “threading”, which basically creates a second script to run the code, much like spawn, which i see youve used. i think your problem is caused by threads (created every time the room changes) overlapping

the problem has already been solved

1 Like