Help needed with script

I have a timer but on 4 minutes and 59 seconds it stops counting down.
(There’s more to the script but I’m only showing the timer part of the code.

	while true do
		s = 0
		m = 5
		repeat
			debounce = true
			wait(1)
		    s = s-1
		 	if s == -1 then
				m = m-1
				s = 59
				if m == -1 then
					m = 0
					s = 0
					end
				end
		until s == 0 and m == 0 
		debounce = false--(there's debounce in the script for the other parts of the code.)
		return debounce
	end
end

To better understand how your script works, What is your end goal?

2 Likes

Well, its a part that gives you a gear when you touch it then when you get the gear the timer starts. After that timer is finished you can get the gear again.

1 Like

There are Simpler ways of doing this with a for loop

for i=60,0,-1 do
print(i)--time
wait(1)
end
1 Like

I can see your using Debounces (Which is a Good thing), To turn on and off the Giver But to make it simple I would do something like:

While Debounce == true do
     Debounce = false
     wait(59)
     Denounce = True
end


or


if Player.Touched then
     Debounce = false
     wait(59)
     Denounce = True
end
~~

I have a surface ui displaying the timer. So I want it to go by seconds and minutes.

Wait(1)
works in seconds. so every tick is 1 second long

If the countdown isn’t being displayed to anyone, you don’t have to bother with minutes and seconds; just use seconds:

wait(5 * 60)
debounce = false

If it is going to be displayed then just make a loop and use division and remainders to format it into minutes and seconds

I know that, personally I think minutes and seconds will make it easier to change.

Yes it will but you will have to say wait(1)

The countdown is gonna be displayed to everyone playing.

Just add Minutes to the bigger loop

for m=5,0,-1 do
for s=60,0,-1 do
print(m,":",i)--time
wait(1)
end
end

or another variant

for i = 120, 0, -1 do
    local minutes = math.floor(i/60)
    local seconds = math.floor(i%60)
    clocktext.Text = string.format("%i:%.2i", minutes, seconds)
    wait(1)
end

is this a Type of Timer Script? i Think theres a Mess up in the Script, ill Be Glad to Help Solve This Issue With this Problem DM Me on Discord or here Soda_DevRBLX#8064

Any examples of where I should put the first code.

for i = (5 * 60), 1, -1 do
	m = math.floor(i / 60)
	s = i % 60
	print(m..":"..(s < 10 and "0" or "")..s) -- formatting example 
	wait(1)
end
-- countdown over
debounce = false

You can use a for loop but then check when it reaches 0 then minus 1 off the minutes and add 59 to the seconds. I shall go make a script now and get back to you.

until s == 0 and m == 0 
	debounce = true--(there's debounce in the script for the other parts of the code.)
	return debounce
end

end

Well, its a part that gives you a gear when you touch it then when you get the gear the timer starts. After that timer is finished you can get the gear again. (Timer is displayed for everyone)

Try That if it dosen’t work then Try Retypeing the Script to Make sure theres Not Errors Also turn your Output ON.

1 Like

Output is useful For Checking Errors in Scripts, So you can go back and correct them.

1 Like