This is basically my pathfinding script for the AI, but the problem is that the AI stops running when it reaches a waypoint. I'd like to know how I could prevent it from doing that. I tried to test the magnitude until the next waypoint, but every time I add a loop, it does not work anymore

wait (5)

local Torso = script.Parent.UpperTorso
local Base = workspace.Baseplate.Position
local Humanoid = script.Parent.Humanoid

local Path = game:GetService("PathfindingService"):FindPathAsync(Torso.Position, Base)
local Points = Path:GetWaypoints()

for i,v in pairs (Points) do
	
	local p = Instance.new("Part", workspace)
	p.Anchored = true
	p.CanCollide = false
	p.CFrame = CFrame.new(v.Position)
	p.Size = Vector3.new(1,1,1)
	
end

if Path.Status == Enum.PathStatus.Success then
	
	for i,v in pairs (Points) do
		
		Humanoid:MoveTo(v.Position)
		--The loop that prevents the script from working for some reason
		repeat wait () until (Torso.Position - Base).magnitude <= 3
		if v.Action == Enum.PathWaypointAction.Jump then
			
			Humanoid.Jump = true
			
		end
		
	end
	
end