long story short I wanted to create a repeat until that would count down from a math.random number to 0 and I’d check it by printing the number. The problem is that it isn’t printing anything. Why isn’t it working?
(note: I used this same code for other scripts and in other scripts it prints perfectly fine)
function CountingDown()
repeat
TimeToWait.Value -= 1
print(TimeToWait.Value)
task.wait(1)
until
TimeToWait.Value == 0
TestRackProxPrompt.Enabled = true
TestRackHighlight.Enabled = true
end
Alright here are the core components of the script.
function CountingDown()
repeat
TimeToWait.Value -= 1
print(TimeToWait.Value)
task.wait(1)
until
TimeToWait.Value == 0
TestRackProxPrompt.Enabled = true
TestRackHighlight.Enabled = true
end
function Uploading()
if CanStart == true and StartedCycleValue == false then
TimerValue.Value = math.random(5, 6)
CanStart = false
StartedCycleValue = true
MonitorHighlight.Enabled = true
MonitorHighlight2.Enabled = false
local NewScriptCopy = game.ServerStorage.RepeatScript:Clone()
NewScriptCopy.Parent = game.Workspace.SampleTesting
if TimerValue.Value == 0 then
NewScriptCopy:Destroy()
MonitorProxPrompt.Enabled = false
MonitorHighlight.Enabled = false
MonitorHighlight2.Enabled = false
TimeToWait.Value = math.random(3, 5) --here is the math.random
HowMany.Value += 1
print(HowMany.Value) --btw this also doesn't print
HardReset() --this one is working
CountingDown() --calling the function here
end
end
end
Also is the TimeToWait a stringvalue or a numbervalue? If its a stringvalue, change it to numbervalue because math.random() returns a number and not a string.
Oh and also if this doesn’t work then change HowMany to a numbervalue aswell.
HowMany is a external value for a Info Gui I created so I won’t have to open the output bar. And its keeping track how many times the Uploading() function repeated itself.
TimeToWait is a number value.
HowMany is also a number value.
After that can you click Run and then do whatever you need to do and then go to wherever you have stored HowMany and TimeToWait and click it. You should see a number if it works or not.
Nothing changes in those 2 values. I don’t really understand whats wrong because there is a exact replica of this code in a different script (changed a bit but core idea is still the same) and it works perfectly fine.
I believe this is because you are setting TimerValue.Value to a random number between 5 and 6, and then if its zero you call CountingDown, except it obviously cannot be zero, since you just set it to a random number between 5 and 6, I think your problem could be solved if you moved the call to CountingDown to be above the if statement.
EDIT: After reading your code I feel it necessary to mention that if anything were attempting to modify the TimerValue.Value, this code would not actually pick up on it since it only checks if TimerValue.Value is zero once, immediately after setting it, if something outside of this script is attempting to modify TimerValue.Value so as to trigger the if statement, you would need to wrap the if statement in a TimerValue.Changed event.
Sorry to be the bearer of bad news but you focused on the wrong value. You were talking about TimerValue but the problem is with TimeToWait Value. And its my fault because I named them so similarly. But still I appreciate your help and your engagement!
Ah, no, I mean you only start counting down TimeToWait if TimerValue is equal to zero, except it can’t be since you just set it to math.random(5,6), so you never call the CountingDown() function, no?
There is a external script that counts down the TimerValue. Its external because I was experimenting with cloning and destroying scripts. And there are other values in this script because I wanted to hook this script up to “Electricity” in a way that there is a external power value that if it is = 1 then the whole place loses power. But it didn’t work out anyways so I just have it running on all the time without checking for power.