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
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.
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.
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.
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.
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.”