Pathfinding NavMesh behaving weirdly

  1. What do you want to achieve?
    Make a NPC pathfind to the nearest “Enemy” NPC

  2. What is the issue?
    The NavMesh appears after my NPC tries to pathfind and fails. path.Status returns Enum.PathStatus.NoPath

  3. What solutions have you tried so far?
    I’ve tried to look for solutions on the devforum but none is encountering it…

Before error:

After error:

Error:
image

Code:

function trackNPC(npcToTrack,selfNpc)


	local character = selfNpc
	local blockedConnection
	local hmd = character:WaitForChild("HumanoidRootPart").Position
	local humanoid = character:WaitForChild("Humanoid")
	local destination
	if typeof(npcToTrack) == "Vector3" then
		destination = npcToTrack
	else
		destination = npcToTrack:FindFirstChild("HumanoidRootPart").Position
	end
	local waypointIndex = 0

	local success, errorMessage = pcall(function()
		path:ComputeAsync(hmd, destination)
	end)
	print(path.Status)
	wait(1)
	if success then
		blockedConnection = path.Blocked:Connect(function(blockedWaypointIndex)
			if blockedWaypointIndex >= waypointIndex then
				blockedConnection:Disconnect()
				trackNPC(npcToTrack,selfNpc)
			end

		end)
		for i,waypoint in pairs(path:GetWaypoints()) do
			waypointIndex = i
			print(i)
			humanoid:MoveTo(waypoint.Position)
			humanoid.MoveToFinished:Wait()
		end
		blockedConnection:Disconnect()
	else
		print("failed to compute: " .. tostring(errorMessage))
	end
end

Also just so you know the blocks also are generated using a script:
(before game start)

Fixed! Turns out it was trying to pathfind to itself and thats why it caused an issue.

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