Make a loop button with progress

So im currently making a game. But i have some trouble with a button. So the plan is that when you press the button the progress of it goes up by some stuff every 0.1 seconds, and when it hits 100% it goes back to 0 , you gain +1 energy and the loop continues. But it does not work for some reason. Here is the script.

while wait() do
	script.Parent.Text = "Rest ("..game.Players.LocalPlayer.leaderstats.EnergyProgress.Value.."%)"
end

while wait(0.1) do
	if player.leaderstats.EnergyProgressing.Value == true then
		player.leaderstats.EnergyProgress.Value += 1
		if player.leaderstats.EnergyProgress.Value == 100 then
			player.leaderstats.EnergyProgress.Value = 0
			player.leaderstats.Energy.Value += 1
		end
	end
end

script.Parent.MouseButton1Click:Connect(function()
	if player.leaderstats.EnergyProgressing.Value == false then
		player.leaderstats.EnergyProgressing.Value = true
	elseif player.leaderstats.EnergyProgressing.Value == true then
		player.leaderstats.EnergyProgressing.Value = false
	end
end)

The while loop will run until the code executes, since it is infinite - anything after it will not work, you need to use task.spawn
Docs: task | Roblox Creator Documentation

task.spawn(function()
	while wait() do
		script.Parent.Text = "Rest ("..game.Players.LocalPlayer.leaderstats.EnergyProgress.Value.."%)"
	end
end)

task.spawn(function()
	while wait(0.1) do
		if player.leaderstats.EnergyProgressing.Value == true then
			player.leaderstats.EnergyProgress.Value += 1
			if player.leaderstats.EnergyProgress.Value == 100 then
				player.leaderstats.EnergyProgress.Value = 0
				player.leaderstats.Energy.Value += 1
			end
		end
	end
end)

script.Parent.MouseButton1Click:Connect(function()
	if player.leaderstats.EnergyProgressing.Value == false then
		player.leaderstats.EnergyProgressing.Value = true
	elseif player.leaderstats.EnergyProgressing.Value == true then
		player.leaderstats.EnergyProgressing.Value = false
	end
end)