Hello to the person reading this. My script is refusing to stop subtracting a number when it hits 0.
Here is the script
01 | local Inter = Instance.new( "IntValue" ) -- Creates the Value |
02 | Inter.Parent = game.Workspace |
03 | Inter.Name = ( "Intermission" ) |
04 | Inter.Value = 10 |
05 |
06 | while true do |
07 | repeat |
08 | wait( 1 ) |
09 | Inter.Value = Inter.Value - 1 |
10 |
11 | until Inter.Value = = 0 |
12 | end |
Un-necessary to have a repeat
within a while
loop. You can simply edit your while loop by replacing the true with the conditional...
1 | local Inter = Instance.new( "IntValue" ) -- Creates the Value |
2 | Inter.Parent = game.Workspace |
3 | Inter.Name = ( "Intermission" ) |
4 | Inter.Value = 10 |
5 |
6 | while Inter.Value > 0 do |
7 | wait( 1 ) |
8 | Inter.Value = Inter.Value - 1 |
9 | end |
@Uroxus's answer is the correct way to do it.
Below works but isn't correct.
01 | local Inter = Instance.new( "NumberValue" ) -- Creates the Value |
02 | Inter.Parent = game.Workspace |
03 | Inter.Name = ( "Intermission" ) |
04 | Inter.Value = 10 |
05 |
06 | repeat |
07 | if Inter.Value ~ = 0 then |
08 | wait( 1 ) |
09 | Inter.Value = Inter.Value - 1 |
10 | end |
11 | until Inter.Value = = 0 |
A repeat loop checks its condition last, meaning it will always run the code inside at least once. I'm not sure what you're trying to do, but this would fix that problem:
01 | local Inter = Instance.new( "IntValue" ) -- Creates the Value |
02 | Inter.Parent = game.Workspace |
03 | Inter.Name = ( "Intermission" ) |
04 | Inter.Value = 10 |
05 |
06 | while true do |
07 | while Inter.Value ~ = 0 do |
08 | wait( 1 ) |
09 | Inter.Value = Inter.Value - 1 |
10 | end |
11 | wait() |
12 | end |
However this is bad code. Instead a simple for loop would do:
1 | local Inter = Instance.new( "IntValue" ) -- Creates the Value |
2 | Inter.Parent = game.Workspace |
3 | Inter.Name = ( "Intermission" ) |
4 | Inter.Value = 10 |
5 |
6 | for i = Inter.Value, 0 , - 1 do |
7 | wait( 1 ) |
8 | Inter.Value = i |
9 | end |
If this isn't what you wanted please explain in greater detail what you want the code to do.
01 | local Inter = Instance.new( "IntValue" ) -- Creates the Value |
02 |
03 | Inter.Parent = game.Workspace |
04 |
05 | Inter.Name = ( "Intermission" ) |
06 |
07 | Inter.Value = 10 |
08 |
09 | repeat |
10 | wait( 1 ) |
11 | Inter.Value = Inter.Value - 1 |
12 | until Inter.Value = = 0 |
Its an infinite loop. The while true do part kept repeating the repeat wait(1) until part.