Whats wrong with my math.Random rain script

–!GENERATED
local Rain = require(script.Rain)
Promp = game.Workspace.Dig.ProximityPrompt.Enabled

Rain:SetColor(Color3.fromRGB(script.Color.Value.x, script.Color.Value.y, script.Color.Value.z))
Rain:SetDirection(script.Direction.Value)

Rain:SetTransparency(script.Transparency.Value)
Rain:SetSpeedRatio(script.SpeedRatio.Value)
Rain:SetIntensityRatio(script.IntensityRatio.Value)
Rain:SetLightInfluence(script.LightInfluence.Value)
Rain:SetLightEmission(script.LightEmission.Value)

Rain:SetVolume(script.Volume.Value)

Rain:SetSoundId(script.SoundId.Value)
Rain:SetStraightTexture(script.StraightTexture.Value)
Rain:SetTopDownTexture(script.TopDownTexture.Value)
Rain:SetSplashTexture(script.SplashTexture.Value)

local threshold = script.TransparencyThreshold.Value
if script.TransparencyConstraint.Value and script.CanCollideConstraint.Value then
Rain:SetCollisionMode(
Rain.CollisionMode.Function,
function(p)
return p.Transparency <= threshold and p.CanCollide
end
)
elseif script.TransparencyConstraint.Value then
Rain:SetCollisionMode(
Rain.CollisionMode.Function,
function(p)
return p.Transparency <= threshold
end
)
elseif script.CanCollideConstraint.Value then
Rain:SetCollisionMode(
Rain.CollisionMode.Function,
function(p)
return p.CanCollide
end
)
end

local oneSec = 5
local TwoSec = 4
local ThreeSec = 3
local FourSec = 2
local Seconds = 30

RainRandom = math.random(1,4)

if RainRandom == 1 then
Rain:Enabled()
wait(oneSec)
Rain:Disable()

else if RainRandom == 2 then
Rain:Enabled()
wait(TwoSec)
Rain:Disable()

else if  RainRandom == 3 then
		Rain:Enabled()
		wait(ThreeSec)
		Rain:Disable()
		
	else if  RainRandom == 4  then
			Rain:Enabled()
			wait(FourSec)
			Rain:Disable()
		end
	end
end

end

Blockquote

Idk why my script looks like that but I’m trying to make rain happen randomly using math.random and it ain’t working any help

What is the error? Please be more specific and adjust your block code, I can’t read it well.

Format your code first by adding ``` at top and bottom of your code.

local Rain = require(script.Rain)
Promp = game.Workspace.Dig.ProximityPrompt.Enabled

Rain:SetColor(Color3.fromRGB(script.Color.Value.x, script.Color.Value.y, script.Color.Value.z))
Rain:SetDirection(script.Direction.Value)

Rain:SetTransparency(script.Transparency.Value)
Rain:SetSpeedRatio(script.SpeedRatio.Value)
Rain:SetIntensityRatio(script.IntensityRatio.Value)
Rain:SetLightInfluence(script.LightInfluence.Value)
Rain:SetLightEmission(script.LightEmission.Value)

Rain:SetVolume(script.Volume.Value)

Rain:SetSoundId(script.SoundId.Value)
Rain:SetStraightTexture(script.StraightTexture.Value)
Rain:SetTopDownTexture(script.TopDownTexture.Value)
Rain:SetSplashTexture(script.SplashTexture.Value)

local threshold = script.TransparencyThreshold.Value
if script.TransparencyConstraint.Value and script.CanCollideConstraint.Value then
	Rain:SetCollisionMode(
		Rain.CollisionMode.Function,
		function(p)
			return p.Transparency <= threshold and p.CanCollide
		end
	)
elseif script.TransparencyConstraint.Value then
	Rain:SetCollisionMode(
		Rain.CollisionMode.Function,
		function(p)
			return p.Transparency <= threshold
		end
	)
elseif script.CanCollideConstraint.Value then
	Rain:SetCollisionMode(
		Rain.CollisionMode.Function,
		function(p)
			return p.CanCollide
		end
	)
end

local oneSec = 5
local TwoSec = 4
local ThreeSec = 3
local FourSec = 2
local Seconds = 30


RainRandom = math.random(1,4)

if RainRandom == 1 then
	Rain:Enabled()
	wait(oneSec)
	Rain:Disable()
	
else if  RainRandom == 2 then
		Rain:Enabled()
		wait(TwoSec)
		Rain:Disable()
		
	else if  RainRandom == 3 then
			Rain:Enabled()
			wait(ThreeSec)
			Rain:Disable()
			
		else if  RainRandom == 4  then
				Rain:Enabled()
				wait(FourSec)
				Rain:Disable()
			end
		end
	end
end ```

There’s no error it’s just the rain never starts

1 Like
local Rain = require(script.Rain)
Promp = game.Workspace.Dig.ProximityPrompt.Enabled

Rain:SetColor(Color3.fromRGB(script.Color.Value.x, script.Color.Value.y, script.Color.Value.z))
Rain:SetDirection(script.Direction.Value)

Rain:SetTransparency(script.Transparency.Value)
Rain:SetSpeedRatio(script.SpeedRatio.Value)
Rain:SetIntensityRatio(script.IntensityRatio.Value)
Rain:SetLightInfluence(script.LightInfluence.Value)
Rain:SetLightEmission(script.LightEmission.Value)

Rain:SetVolume(script.Volume.Value)

Rain:SetSoundId(script.SoundId.Value)
Rain:SetStraightTexture(script.StraightTexture.Value)
Rain:SetTopDownTexture(script.TopDownTexture.Value)
Rain:SetSplashTexture(script.SplashTexture.Value)

local threshold = script.TransparencyThreshold.Value
if script.TransparencyConstraint.Value and script.CanCollideConstraint.Value then
	Rain:SetCollisionMode(
		Rain.CollisionMode.Function,
		function(p)
			return p.Transparency <= threshold and p.CanCollide
		end
	)
elseif script.TransparencyConstraint.Value then
	Rain:SetCollisionMode(
		Rain.CollisionMode.Function,
		function(p)
			return p.Transparency <= threshold
		end
	)
elseif script.CanCollideConstraint.Value then
	Rain:SetCollisionMode(
		Rain.CollisionMode.Function,
		function(p)
			return p.CanCollide
		end
	)
end


	Rain:Enabled() ```


Original script

Add prints to each of the lines to figure out where it stops, although I’m sure your error is here:

if script.TransparencyConstraint.Value and script.CanCollideConstraint.Value then

Make sure that both these conditions are what you expect them to be.

1 Like