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

This keeps looping forever even though it's supposed to stop when db_value is 0?

Asked by 4 years ago

So I have my code here.

1db_value.Value = db
2repeat wait(1)
3db_value =  db_value -1
4print(db_value)
5until db_value == 0 --> This is supposed to loop it until the value reaches 0, right?
6end

This code just loops infinitely even though my goal is to stop it once it reaches 0, how can I fix this?

3 answers

Log in to vote
1
Answered by
DevingDev 346 Moderation Voter
4 years ago
Edited 4 years ago

I already fixed this problem when answering your last question, but I don't mind answering again.

You're forgetting to include .Value after the db_value variable on line 3 and line 5.

1db_value.Value = db
2repeat
3    wait(1)
4    db_value.Value =  db_value.Value -1
5    print(db_value.Value)
6until db_value.Value <= 0
7end
0
Yeah, I changed it to local db_value = script.Parent.db.Value VoidKeyword 111 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

you can do this;

1db_value.Value = db
2repeat wait(1)
3if db_value ~= 0 then
4db_value =  db_value -1
5print(db_value)
6end
7until db_value == 0 --> This is supposed to loop it until the value reaches 0, right?
8end
Log in to vote
0
Answered by 4 years ago

Instead of using repeat, I'd do this:

1while db_value > 0 do
2    db_value =  db_value -1
3    print(db_value)
4end

Answer this question