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.

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

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.

db_value.Value = db
repeat 
    wait(1)
    db_value.Value =  db_value.Value -1
    print(db_value.Value)
until db_value.Value <= 0
end
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;

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

Instead of using repeat, I'd do this:

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

Answer this question