My round timer isn't working

Hello there! So I ran into a problem… I have this round timer, which basically counts from x value and when it hits 0, it SHOULD stop. Although while testing, it seems to stop at 2, so does it in my output. Really confused on this.

My code:

local Status = game.ReplicatedStorage:WaitForChild("Status")
for  i = 10,0, -1 do
	wait(1)
	print(i)
	
	Status.Value = "My Text here (" ..i..")" 
	
	if i == 0 then
		Status.Value = ""
	end
end

Picture of my output stopping at 2:
image

Any help is appreciated! :slight_smile:

1 Like

Unrelated, but you’re getting the StarterGui which is replicated across the server & not the individual client :thinking:

That shouldn’t be the case though? A for loop should stop once it reaches its end goal (Or 0)

The more I look at this the more confused I get. I don’t see any possible place for error, as your for loop should naturally traverse from 10 to 0, decrementing by 1 every loop.

Something I would do is remove the space before the -1 in the for loop statement (Consistency OCD) in case that changes anything.

Wish I could help more, but I hope you’ll be able to fix it!

I have a IntValue which waits 10 seconds, and this scripts basically counts from 10 to 0, I believe the IntValue runs faster when the game is ran, and the scripts gets a delay by some seconds making it stop before the IntValue is done waiting 10 seconds?

That was also my initial thought, which is why I was going to suggest you to play with the wait() function. However, it doesn’t make sense that the client/server runtime or speed would affect how many times a for loop will loop. Thus I figured that wouldn’t play any part in what numbers are printed in the console.

But then again, you might as well try it out? Let me know how changing that part goes.

I actually have did some changes to the wait, but changing that makes the count faster. Although let me check 1 more time!

Hello there!

At first glance here, I see no source of error. Through further investigation and testing, the code works flawlessly in my own studio application.

I have reason to believe this is not the whole script you’re giving us, I just want confirmation that it is the whole script you’re giving us. As I see no discrepancies which could be giving you this type of error.

Once this question is answered, I can proceed in helping you troubleshoot.

Thanks! <3

1 Like

Why don’t you use repeat until?

Instead of for i = do repeat until Its what I use I’m not forcing you to just saying

1 Like

For loops like the one given above are far more accurate and useful for the type of thing he wants, which is a timer.

Its just easier to do though
Here is a example

local t = 20
repeat
t = t - 1
wait(1)
print(t)
until t == 0

How it works is that once I click a button, a map gets cloned into workspace which has my script inside and the IntValue. Everything works, the intvalue waits 10 seconds but the GUI counts until 2 and nothing happens.

Add a print() and see if it gets printed

Tbh I never really understood how repeat until & for do loops worked, but personally I just use for do more cause they’re more easier & simpler to understand

Otherwise, it’d make no difference regardless & it’d make the script a bit more complicated than what it needs to be

Just using repeat is simple and I use it for my minigame script for a rising lava if you want to know where my topic on my rising lava is here: Feedback on my rising lava

See, a chunk of code like so is far more complicated than a simple timer needs to be. The for loop lets you run a command or group of commands a set number of times.

You can read more here.

1 Like

If I may ask, what chunk of code changes the GUI Label?

I’m just use to it and it works very well just why is it for checking or something

I think if you provided nino (or the post in general) with more complete code from your script and the portions related to the code, then it would help us help you. I agree with nino, as “At first glance here, I see no source of error.”

Wish you the best of luck!

1 Like

Its a while true do that does it or he can use the .changed event but for some reason it wasn’t working for me before so I used while true do