What am I doing wrong with this rain script?

I’m trying to make a weather system using BuildThomas’s rain module, and I’m having some issues.

I don’t think my code is running altogether, and I’m not getting any errors.

LocalScript: (In ServerScriptService)

local event = game.ReplicatedStorage:WaitForChild("RainEvent")

while true do
	local randomnumber = math.random(1,3) -- I changed it so that it should have run every time

	if randomnumber ==  1 then
		local num = randomnumber
		event:FireServer(num)
		print("fired")
	elseif randomnumber == 2 then
		local num = randomnumber
		event:FireServer(num)
		print("fired")
	elseif randomnumber == 3 then
		local num = randomnumber
		event:FireServer(num)
		print("fired")
	end
	wait(40)
end

BindableEvent is in ReplicatedStorage.

Script in ServerScriptService:

local event = game.ReplicatedStorage:WaitForChild("RainEvent")
rainmod = require(script.Parent.Rain)
rainmod:Disable()

event.OnServerEvent:Connect(function(num)
	print(num)
	if num == 1 then
		rainmod:SetTransparency(0)
		rainmod:SetSpeedRatio(1)
		rainmod:SetIntensityRatio(1)
		rainmod:Enable()
		wait(60)
		rainmod:Disable()
	elseif num == 2 then
		rainmod:SetTransparency(0.4)
		rainmod:SetSpeedRatio(0.6)
		rainmod:SetIntensityRatio(0.6)
		rainmod:Enable()
		wait(40)
		rainmod:Disable()
	elseif num == 3 then
		rainmod:SetTransparency(0.6)
		rainmod:SetSpeedRatio(1)
		rainmod:SetIntensityRatio(0.3)
		rainmod:Enable()
		wait(30)
		rainmod:Disable()
	end
	wait(40)
end)

Could anyone help me debug? Thanks!

Local scripts do not run in servercriptservice, they only run if they are in:

You need to pass the player as the first variable instead.

the 5th line of the server script should be event.OnServerEvent:Connect(function(player,num) instead

1 Like

I’m getting this error after putting the LocalScript in StarterPlayerScripts, and changing the 5th line of the Server Script.

image

Rain is the module by BuildThomas.

Why not just make it all in one server script:

rainmod = require(script.Parent.Rain)
rainmod:Disable()

while wait() do
    local num = math.random(1,3)
	print(num)
	if num == 1 then
		rainmod:SetTransparency(0)
		rainmod:SetSpeedRatio(1)
		rainmod:SetIntensityRatio(1)
		rainmod:Enable()
		wait(60)
		rainmod:Disable()
	elseif num == 2 then
		rainmod:SetTransparency(0.4)
		rainmod:SetSpeedRatio(0.6)
		rainmod:SetIntensityRatio(0.6)
		rainmod:Enable()
		wait(40)
		rainmod:Disable()
	elseif num == 3 then
		rainmod:SetTransparency(0.6)
		rainmod:SetSpeedRatio(1)
		rainmod:SetIntensityRatio(0.3)
		rainmod:Enable()
		wait(30)
		rainmod:Disable()
	end
end

It doesn’t run at all, why is that?

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.