Hello to the person reading this. My script is refusing to stop subtracting a number when it hits 0.
Here is the script
local Inter = Instance.new("IntValue") -- Creates the Value Inter.Parent = game.Workspace Inter.Name = ("Intermission") Inter.Value = 10 while true do repeat wait(1) Inter.Value = Inter.Value -1 until Inter.Value == 0 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...
local Inter = Instance.new("IntValue") -- Creates the Value Inter.Parent = game.Workspace Inter.Name = ("Intermission") Inter.Value = 10 while Inter.Value > 0 do wait(1) Inter.Value = Inter.Value - 1 end
@Uroxus's answer is the correct way to do it.
Below works but isn't correct.
local Inter = Instance.new("NumberValue") -- Creates the Value Inter.Parent = game.Workspace Inter.Name = ("Intermission") Inter.Value = 10 repeat if Inter.Value ~= 0 then wait(1) Inter.Value = Inter.Value -1 end 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:
local Inter = Instance.new("IntValue") -- Creates the Value Inter.Parent = game.Workspace Inter.Name = ("Intermission") Inter.Value = 10 while true do while Inter.Value ~= 0 do wait(1) Inter.Value = Inter.Value -1 end wait() end
However this is bad code. Instead a simple for loop would do:
local Inter = Instance.new("IntValue") -- Creates the Value Inter.Parent = game.Workspace Inter.Name = ("Intermission") Inter.Value = 10 for i = Inter.Value, 0, -1 do wait(1) Inter.Value = i end
If this isn't what you wanted please explain in greater detail what you want the code to do.
local Inter = Instance.new("IntValue") -- Creates the Value Inter.Parent = game.Workspace Inter.Name = ("Intermission") Inter.Value = 10 repeat wait(1) Inter.Value = Inter.Value -1 until Inter.Value == 0
Its an infinite loop. The while true do part kept repeating the repeat wait(1) until part.