What am I doing wrong with this rain script?

Oh probably because the while wait() function waits first then runs the code and repeats. Retry it now, I just fixed it.

I’m getting the error again:
image

It’s probably because there’s soemthing in the rain script that can only be ran in a local script because it has RenderStepped in it. Try it in a local script

1 Like

Didn’t work, that’s how I got the error.

Would where I placed the LocalScript matter?

Put the code @XdJackyboiiXd21 made in a localscript and put it in StarterPlayerScripts in this case perhaps, jsut anywhere a local script can work

Should I change the

rainmod = require(script.Parent.Rain)

or put the module in the same place?

Put the module anywhere you want I believe, I recommend putting it in ReplicatedStorage and changing that line to

rainmod = require(game.ReplicatedStorage.Rain)
1 Like

It works now, but would the rain only run for the local player? I want it to run for the whole server, if that’s possible.

It would run for each player if done like this, meaning every player is going to see the rain since they each have the rain script

1 Like

If I set the math.random to something else, would each player get a different number?

Yea that’s the only thing that’s a problem, each will see different rain basically, you’d have to find a way to make it the same for everyone

1 Like

Do you know a way I could possibly accomplish that?

You could put an intvalue in replicated storage. Have a server script change the int value and have the local scripts reference that value.

The issue with that is that all 3 of those statements have different waits, so he’d probably have to make it wait the longest it would be before rain changes, maybe every 65 seconds the value changes to be safe

Would setting all the waits to the same thing make it work better? (The waits differences aren’t neccessary)

If you want, if you made all of them 60 for example, you could make the wait in the server change the value randomly every 60.1 seconds to make sure it’s randomized before the clients can reference it

1 Like

Like this?

while wait() do

local num = math.random(0,12)

script.Parent.Value = num

wait(60.1)

end

(sorry about formatting)

while true do

local num = math.random(0,12)

script.Parent.Value = num

wait(60.1)

end

I recommend putting the BaseValue itself i nReplicatedStorage, where you put the rain module too, and make the local scripts get that value from ReplicatedStorage and use that

1 Like

The script would still be in the value, correct?