Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

I have a timer gui model for my game but I need it to reset when it hits zero how do I do this?

   while true do
wait (1)
if script.Parent.Text == "0" then return end 
script.Parent.Text = script.Parent.Text -1
    end

I need the timer to reset at zero but I don't know how to do this there's no tutorials about this or anything, please help.

1 answer

✓ Accepted answer

It is better to use a for loop instead as it is more efficient. Also, return is for functions. To end a loop, you would use break

Here is what you do:

local seconds = 60 -- change this to how long you want your timer to run for
while true do -- to loop the timer.
	for i = seconds,0,-1 do
		script.Parent.Text = tostring(i)
		wait(1)
	end
	script.Parent.Text = seconds
end

10 comments

0

Then how could I loop it?

0

Just put a while true do loop around the for loop.

0

Where exactly would I put a while true do at what line?

0

put "while true do" at line 2 and "end" on line 8.

0

Do I put anything near while do true? Cause when I try it, it doesn't work.

0

What does the output say?

0

It says expected 'do', got 'script'.

0

I've edited the script above. Try using that.

0

Thank you so much it works just one more problem when I die it resets the whole timer is there any way I can fix this problem too?

0

Inside the ScreenGui that it's in, there should be a property named "ResetOnSpawn". Uncheck that.

This discussion is preserved as it was. New answers, comments, and votes are closed.