Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why does this code lag the server to the point where roblox has to timeout even with a wait?

Asked by 4 years ago
1db_value.Value = db
2repeat until db_value.Value == 0
3wait(1)
4db_value.Value =  db_value -1
5print(db)
6end

So I'm making a debounce and I wanna repeat this, code is pretty self-explanatory. Why does it pretty much crash studio and how can I fix that?

1
It Lags Because You Didn't Put The Code Before The Until. Harry_TheKing1 325 — 4y
0
Nice answer. JesseSong 3916 — 4y

3 answers

Log in to vote
1
Answered by 4 years ago

you can change it with this:

1db_value.Value = db
2repeat wait()
3db_value.Value =  db_value -1
4print(db)
5until db_value.Value == 0
6end
Ad
Log in to vote
1
Answered by
DevingDev 346 Moderation Voter
4 years ago
Edited 4 years ago

This is because you're not doing anything inside of the repeat-until statement.

The code you want to be repeated until it's condition is true has to be inside of the repeat-until statement.

1repeat
2    print(I'll be printing forever. True will never equal false.)
3    wait()
4until true == false

The code above will print forever since true will never equal false. That was an example of how you could use it.

You could also use it like this, which will fit your needs perfectly.

1db_value.Value = db
2repeat
3    wait(1)
4    db_value.Value = db_value.Value -1
5    print(db)
6until db_value.Value <= 0
7print("db_value equals 0 or less.")

If you want to read more about repeat-until statements then feel free to look at the pil.

0
Nice answer JesseSong 3916 — 4y
0
Also shouldn't you add an end since all loops and if statements require an end? JesseSong 3916 — 4y
0
The repeat-until statement doesn't require an end. I don't know what he's doing before this, but this works. DevingDev 346 — 4y
Log in to vote
0
Answered by
JesseSong 3916 Moderation Voter Community Moderator
4 years ago

Reading from what @Harry_TheKing1 said basically, your script renders so fast because there's no wait and you didn't put the below code after the until function after

1db_value.Value = db
2repeat
3wait(.5)
4db_value.Value =  db_value -1
5print(db)
6until db_value.Value == 0
7end

Answer this question