local G local R local function d(d)path:ComputeAsync(zombie.Position,d)G={}if path.Status==Enum.PathStatus.Success then G=path:GetWaypoints()R=1 human:MoveTo(G[R].Position)else human:MoveTo(zombie.Position)end end local function q(d)if d and(G~=nil and(R~=nil and R<#G))then R=R+1 human:MoveTo(G[R].Position)end end local function E(G)if G>R then d(destination)end end
-- Variables to store waypoints table and zombie's current waypoint
local waypoints
local currentWaypointIndex

local function followPath(destinationObject)
	-- Compute and check the path
	path:ComputeAsync(zombie.Position, destinationObject)
	-- Empty waypoints table after each new path computation
	waypoints = {}

	if path.Status == Enum.PathStatus.Success then
		-- Get the path waypoints and start zombie walking
		waypoints = path:GetWaypoints()
		-- Move to first waypoint
		currentWaypointIndex = 1
		human:MoveTo(waypoints[currentWaypointIndex].Position)
	else
		-- Error (path not found); stop humanoid
		human:MoveTo(zombie.Position)
	end
end

local function onWaypointReached(reached)
	if reached and waypoints ~= nil and currentWaypointIndex ~= nil and currentWaypointIndex < #waypoints then
		currentWaypointIndex = currentWaypointIndex + 1
		human:MoveTo(waypoints[currentWaypointIndex].Position)
	end
end

local function onPathBlocked(blockedWaypointIndex)
	-- Check if the obstacle is further down the path
	if blockedWaypointIndex > currentWaypointIndex then
		-- Call function to re-compute the path
		followPath(destination)
	end
end
