Help returning out of while loop to end loop

Hey devs!

Just a quick question! I may be completely overthinking/overlookin the problem, but essentially what I am trying to accomplish is a way to exit a loop, without using BREAK and keeping the loop in tact to be ran again.

I am creating a timer like how sports have periods. Once this timer is up, I want it to then wait 5 seconds, and then reset(just visible in text, the remote handles the actual resetting of the clock on the server), but I want this code to be run again on .Changed(which happens when you press the gui button to start the clock.

Just wondering what may be wrong or what I am overlooking, or if I am completely just out of touch with how this is supposed to be completed lol. All help’s appreciated!
(Ignore the “Steps”, for my essay of troubleshooting lol)
Also important to note; this is being done on a LocalScript

value.Changed:Connect(function()
	if value.Value == true and timer >= 1 then
		
		while true do
			wait(.1)
			if value.Value == true then
				print("Step1")
				for i = timer,1,-1 do
					script.Parent.Text = ""..format(math.floor(i))
					timer = timer - 1
					runClock:FireServer(timer)
					wait(1)
					print("Step2")

					if i == 0 or timer == 0 then
						print("Step3")
						script.Parent.Text = "End of Period"
						wait(5)
						script.Parent.Text = "10:00"
						resetTime:FireServer()
						wait(1)
						print("Step4")
						return 
					end

					if value.Value == false and i >= 1 then
						wait(1)
						return 
					end
					

				end
				print("Step5")
			end
			wait(.1)
		end

		
	elseif value.Value == false then
		print("do nothing")
		return
	end
	
end)

1 Like

disable and enable the script

script.Disabled = true
script.Disabled = false

1 Like

Figured it out myself after posting this thread lol.

Answer; Reset a local version of the timer values.

1 Like