For loop for pathfinding is not running at all

I was just creating a pathfinding module for myself and tried it out, but the for loop inside of it did not even run. Does anyone know why. There are no errors, here is the script:

function PathFinding:StartPath(CurrentStage, CPUSpawnPos, End)
	local PathFindingService = game:GetService('PathfindingService')
	local pathToMoveOn = PathFindingService:CreatePath()
	local AI = game.Workspace.AllStages[CurrentStage].Robot
	local humanoid = AI.Humanoid
	
	print("Running Path")
	
	
	local pathToMoveOn = PathFindingService:CreatePath()

	

	pathToMoveOn:ComputeAsync(AI.HumanoidRootPart.Position, End)

	local wayPoints = pathToMoveOn:GetWaypoints()
	for _, WayPoint in pairs(wayPoints) do
		if WayPoint.Action == Enum.PathWaypointAction.Jump then
			humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
			local Sphere = Instance.new("Part")
			Sphere.Shape = "Ball"
			Sphere.Material = "Neon"
			Sphere.Size = Vector3.new(0.6,0.6,0.6)
			Sphere.Anchored = true
			Sphere.CanCollide = false
			Sphere.Parent = workspace
			Sphere.Position = WayPoint.Position + Vector3.new(0,3,0)

			humanoid:MoveTo(WayPoint.Position)
			humanoid.MoveToFinished:Wait()
		else
			humanoid:ChangeState(Enum.HumanoidStateType.Running)
			local Sphere = Instance.new("Part")
			Sphere.Shape = "Ball"
			Sphere.Material = "Neon"
			Sphere.Size = Vector3.new(0.6,0.6,0.6)
			Sphere.Anchored = true
			Sphere.CanCollide = false
			Sphere.Parent = workspace
			Sphere.Position = WayPoint.Position + Vector3.new(0,3,0)

			humanoid:MoveTo(WayPoint.Position)
			humanoid.MoveToFinished:Wait()
		end


	end
end

Edit: The Parts I was creating were just to see if the loop was actually running.

Have you tried printing out the status before looping through waypoints to make sure it successfully found a path?

print(pathToMoveOn.Status)

What would I do if it did not find a path?

I tried fixing it and it did not work, not even character.Humanoid:MoveTo worked.

Then you would tell the Humanoid to create a new path again.

Ok, I did and it still does not walk on the other.