This is what I put in the script It works however, the AI goes to my previous location before going to my new one. Is there a way I can recompute the path while it's still moving?





local pathService = game:GetService("PathfindingService")

local finish = nil
wait(1)
script.Parent.HumanoidRootPart:SetNetworkOwner(nil)

function findNearestTorso(pos)
	local list = game.Workspace:children()
	local torso = nil
	local dist = 500
	local temp = nil
	local human = nil
	local temp2 = nil
	for x = 1, #list do
		temp2 = list[x]
		if (temp2.className == "Model") and (temp2 ~= script.Parent) then
			temp = temp2:findFirstChild("HumanoidRootPart")
			human = temp2:findFirstChild("Humanoid")
			if (temp ~= nil) and (human ~= nil) and (human.Health > 0) then
				if (temp.Position - pos).magnitude < dist then
					torso = temp
					dist = (temp.Position - pos).magnitude
				end
			end
		end
	end
	return torso
end

function followPath(path)
	local points = path:getWaypoints()
	
	for index, point in pairs(points) do
		if point.Action == Enum.PathWaypointAction.Walk then
			script.Parent.Humanoid:MoveTo(point.Position)
			script.Parent.Humanoid.MoveToFinished:Wait()

		end
		if point.Action == Enum.PathWaypointAction.Jump then
			script.Parent.Humanoid.Jump = true
		end
	end
end

while wait() do
	
	local finish = findNearestTorso(script.Parent.HumanoidRootPart.Position)
	if finish ~= nil then 
		local getPath = pathService:ComputeRawPathAsync(script.Parent.HumanoidRootPart.Position,finish.Position,500)
	followPath(getPath)
	end
	
end