Pathfinding script lagging

Hello!
So I have a pathfinding script, but it lags!
What I mean:
If I move, it takes a few seconds before the npc starts going to my new position!
Why?
Script:

local function pathFind()
	
	local target = getTarget()
	
	if target then
		
	
		local path = getPath(target)
	
		if path.Status == Enum.PathStatus.Success then
			
			
			local waypoints = path:GetWaypoints()
			
			for _, waypoint in pairs(waypoints) do
				humanoid:MoveTo(waypoint.Position)
				local timeOut = humanoid.MoveToFinished:Wait(1)
				if not timeOut then
					humanoid:MoveTo(target.HumanoidRootPart.Position - (doge.HumanoidRootPart.CFrame.LookVector * 10))
				end
			end
			
		else
			
			humanoid:MoveTo(target.HumanoidRootPart.Position - (doge.HumanoidRootPart.CFrame.LookVector * 10))
			
		end
	end
end

while wait() do
	pathFind()
end
	

No errors, thanks for any help!

Are there any commands preventing this from running on time? aka wait()?

Why are you bumping this? I solved this 2 months ago, don’t expect it’s not solved. Why didn’t you message me rather than bump this?

…? you never closed it and it was on the front page of latest…?