AI not following player

I’m trying to have an AI follow the player but stay behind by 10
It prints out that the player is Far enough away but doesn’t walk to the player.
I’m super confused!

Heres the script:

local function WalkTo(humanoid,destination,AI)

		local path = Getpath(humanoid.Parent,destination)
		if path.Status == Enum.PathStatus.Success then
			for index, waypoint in pairs(path:GetWaypoints()) do
					
					humanoid:MoveTo(waypoint.Position)
					while true do
						local distance = (AI.HumanoidRootPart.Position - waypoint.Position).Magnitude
						local distance_From_Player = (AI.HumanoidRootPart.Position - game.Players:GetPlayers()[1].Character.HumanoidRootPart.Position).Magnitude
						if distance > 5 then
							break	
						end
						if distance_From_Player < 10 then
							humanoid:MoveTo(AI.HumanoidRootPart.CFrame*CFrame.new(0,0,-3).p)
							print("Player Too Close")
							break
						else
							print("Far Enough Away")
						end
						
						wait()
					end
					--humanoid.MoveToFinished:Wait()
				
			end
		else
			--print("PathBlocked")
		end

end

If you need more info ask!

Do you call WalkTo() just one time? If so, you’ll need to fix that, and call it more often. The reason why is because when you get the path, you give the current position of the player. As the player moves, they are no longer at that old position, thus making the bot not move towards the most updated position of the player.