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

Why NumberValue does not reset once it hits 0? Just goes into negatives

Asked by 7 years ago
Edited 7 years ago

Like the most basic thing and i'm having a problem with it. It's just a count down thing. Two number Values and once the seconds hit 0 its supposed to go back to 60 and drop a minute. But the timer just keeps counting down into the negatives.

01local min = script.Minutes
02local sec = script.Seconds
03local night = script.Night
04 
05while true do
06    wait(1)
07    sec.Value = sec.Value - 1
08end
09 
10sec.Changed:connect(function()
11    if sec == 0 then
12        sec.Value = 60
13        min.Value = min.Value - 1
14    end
15end)

Any help is appreciated!

Edit: Sorry I worded the title terribly. I just could not think of a way to ask this.

1 answer

Log in to vote
2
Answered by
mattscy 3725 Moderation Voter Community Moderator
7 years ago

On line 11, you check if the value instance is equal to 0, when you should be checking if the value’s value is equal to 0.

1if sec.Value == 0 then

instead of

1if sec == 0 then
Ad

Answer this question