Scripting Helpers is winding down operations and is now read-only. More info→
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 5 years ago
Edited 5 years 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 — 5y
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 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

Please format code properly.

This is your code right now.

01while true do
02    workspace.Rain.RainEffect.RainScript.Enabled = false
03    workspace.Snow.SnowEffect.SnowScript.Enabled = false
04 
05    do
06        math.random(1,2)
07        wait()
08        if math.random == 1 then
09            workspace.Rain.RainEffect.RainScript.Enabled = true
10            wait(160)
11            if math.random == 2 then
12                workspace.Snow.SnowEffect.SnowScript.Enabled = true
13                wait(160)
14        end
15    end
16end

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:

01while true do
02    workspace.Rain.RainEffect.RainScript.Enabled = false
03    workspace.Snow.SnowEffect.SnowScript.Enabled = false
04 
05    do
06        local num = math.random(1,2)
07        wait()
08        if num == 1 then
09            workspace.Rain.RainEffect.RainScript.Enabled = true
10            wait(160)
11        else
12            workspace.Snow.SnowEffect.SnowScript.Enabled = true
13            wait(160)
14        end
15    end
16end

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 — 5y
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 — 5y
Ad

Answer this question