I created a script to set the weather randomly and to loop; Roblox shows no errors in the script. I was wondering if the math.random is incorrect. The script was created to block one script as another runs. The script:
while true do workspace.Rain.RainEffect.RainScript.Enabled = false workspace.Snow.SnowEffect.SnowScript.Enabled = false Do math.random(1,2) wait() if num == 1 then workspace.Rain.RainEffect.RainScript.Enabled = true wait(160) if num == 2 then workspace.Snow.SnowEffect.SnowScript.Enabled = true wait(160) end end end
Please format code properly.
This is your code right now.
while true do workspace.Rain.RainEffect.RainScript.Enabled = false workspace.Snow.SnowEffect.SnowScript.Enabled = false do math.random(1,2) wait() if math.random == 1 then workspace.Rain.RainEffect.RainScript.Enabled = true wait(160) if math.random == 2 then workspace.Snow.SnowEffect.SnowScript.Enabled = true wait(160) end end end
Now there are some obvious errors, such as you are missing an end. Also, you can use else instead of making another if statement. Also, you're comparing the function math.random
to a number. Instead, you want to store the random number math.random
generates, and compare that to a number.
(I'm assuming waiting 2 minutes and 40 seconds to perform the snow check is intentional)
You probably want to do something similar to this:
while true do workspace.Rain.RainEffect.RainScript.Enabled = false workspace.Snow.SnowEffect.SnowScript.Enabled = false do local num = math.random(1,2) wait() if num == 1 then workspace.Rain.RainEffect.RainScript.Enabled = true wait(160) else workspace.Snow.SnowEffect.SnowScript.Enabled = true wait(160) end end end
Reply with further questions,
and please mark as correct if this solution works for you!