Ad
Log in to vote
0

I created basic script to understand how to make weather, but It refuses to work, what is wrong?

Asked by 1 year ago
Edited 1 year ago

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

0
Honestly, the script was created to stop other scripts from running as one ran. Both script that were controlled by the main script contained a line that said wait(math.random(1,10)) as an example of random weather. This was made for uncertainty and non-constant weather. However, when the main script that controls the others is placed, the main script doesn't work. ifreakinlostmyacount 52 — 1y
0
When the RainScript and the SnowScript is taken out, then the main script works, but theirs no uncertainty. The other scripts:                                                                                  while true do                                                                                                              script.Parent.Enabled = false --Particles off                        ifreakinlostmyacount 52 — 1y

1 answer

Log in to vote
1
Answered by 1 year ago
Edited 1 year ago

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!

0
Could you use "elseif num == 2 then" on line 11 instead of just "else"? matiss112233 258 — 1y
0
Well, you could, but there's only 2 possibilites. If it's not 1, then it's 2. So I just kept it simpler. RaforawesomeAlt 343 — 1y
Ad

Answer this question