I am trying to make a timer script based on 3 NumberValues and everything except the TimerValue script is working. I am not getting any errors in the output so I have no idea what I could have done wrong.
local MainValue = script.Parent.Parent.MainValue
local TimeToBreakValue = script.Parent.Parent.TimeToBreak
local ActivatedYesOrNoValue = script.Parent.Parent.ActivatedYesOrNo
local ProxPrompt = script.Parent
if ActivatedYesOrNoValue.Value == 2 then
repeat
TimeToBreakValue.Value = TimeToBreakValue.Value - 1
wait(1)
until
TimeToBreakValue.Value == 0
end
if TimeToBreakValue.Value == 0 then
ActivatedYesOrNoValue.Value = 1
MainValue.Value = math.random(1, 2)
end
if TimeToBreakValue.Value >= 0 then
ActivatedYesOrNoValue.Value = 2
end
The script should choose between 1 and 2. Any Ideas why it isn’t working?
1 Like
I’m very confused on the logic in your script. Why is a YesOrNo Value an int value? Shouldn’t it be a boolean? And why are you subtracting it until it’s zero, and then checking if it’s zero later?
3 Likes
YesOrNo Value is there because I have 2 scripts checking if its true or false. 2 is meant for true and 1 for false. I’m subtracting 0 and then checking if it’s zero later because the script is supposed to be reusable
Well I’ll just ignore the logic for now. I’m pretty sure math.random is working perfectly fine. What makes you think it isn’t?
Well the whole behind this script is that is based on random events. Math Random is there to pick a random number and another script reads that number and aligns it to a scenario based to that number. For example if math random picks 1 then its a simple power outage, if math random picks 2 then the plugs exploded. Its not working because when I tested it with a light, the light did not turn off like in the scenario (every scenario has the light turned off). But I think the problem is with TimeToBreak == 0 because the random number doesn’t get picked.
I’ve added prints to every “if then” and everything prints. I have literally no idea what could be wrong.
This probably won’t fix anything yet, but I simplified the code:
local GameMode = script.Parent.Parent.MainValue
local BreakTime = script.Parent.Parent.TimeToBreak
local ActivationState = script.Parent.Parent.ActivatedYesOrNo
local ProxPrompt = script.Parent -- this is unused
if ActivationState.Value == 2 then
task.wait(BreakTime.Value)
BreakTime.Value = 0
end
if BreakTime.Value == 0 then
ActivationState.Value = 1
GameMode.Value = math.random(1,2)
end
Not sure if I fully understand what you’re trying to do yet, sorry.
It seems like if the YesOrNo value is not 2, nothing ever happens.