:GetWaypoints() returns an empty table

Im coding a zombie AI and for some reason when I call GetWaypoints() on my computed path it returns an empty table. I check if the path is successful and run it through a pcall too, model is unanchored and not welded to anything and it will path every once in a while but it doesn’t 90% of the time.

On heartbeat I call this function with the nearest players torso

local function followPath(destination)
	local success, errorMessage = pcall(function()
		path:ComputeAsync(rootPart.Position, destination)
	end)

	if success and path.Status == Enum.PathStatus.Success then
		waypoints = path:GetWaypoints()
		
		local myWaypoints = waypoints
		
		blockedConnection = path.Blocked:Connect(function(blockedWaypointIndex)
			if blockedWaypointIndex >= nextWaypointIndex then
				followPath(destination)
				blockedConnection:Disconnect()
			end
		end)

		if not reachedConnection then
			reachedConnection = hum.MoveToFinished:Connect(function(reached)
				if reached and nextWaypointIndex < #waypoints then
					nextWaypointIndex += 1
					hum:MoveTo(waypoints[nextWaypointIndex].Position)
				else
					reachedConnection:Disconnect()
					blockedConnection:Disconnect()
				end
			end)
		end
		
		for currentWaypointIndex = 2,#waypoints do
			nextWaypointIndex = currentWaypointIndex
			if myWaypoints == waypoints then
				hum:MoveTo(waypoints[currentWaypointIndex].Position)
			else
				break
			end
		end
	end
end

Why are you storing waypoints in a global variable, then storing it again in another variable? Try just using a single variable.

local myWaypoints = path:GetWaypoints()
1 Like

It has 0 effect on the issue I am facing.

Print out path.Status, what does it say?

Its a success, I have the check for success on the path and on the pcall, both turn out true. It returns {} when I print waypoints. I have 0 clue why.

1 Like