How To Make Rain Periodically

Hi i recently made a really cool rain effect in my game, but i was wondering how could i make it rain periodically with the lighting brightness down. Would that be a simple script or a difficult one? And after the rain it goes back to normal? Roblox dev forum puts mp4s as a download link. This is the rain effect

Thanks :grinning:

–Meeskop

5 Likes

Do you mean if the lighting brightness is down, or when it rains periodically you want the lighting brightness down as well?

when it rains lighting brightness down.

I would go about it by running a loop which continues forever where it starts raining and stops raining after a certain amount of time (couldn’t find the page on wait)

It shouldn’t be too difficult in reality. I have not tried something like this before so not sure if this is the best way but it is definitely one way.

1 Like

Creating Intervals


For the rain to start and stop with random intervals. You have to use a math.random(), don’t forget math.randomseed(tick()) to make it even more random.

Assume you have duration with math.random(), a yielding method; example: wait(math.random(5, 30)), a boolean to toggle the rain and of course the rain instances.

Create a function that will loop/is recursive that runs and executes the lines for the rain to toggle on and off for every random range of seconds.

Conclusion


It is not impossible to create such function and therefore the script would look like this:

math.randomseed(tick())

-- The boolean
local RainEnabled = false

-- The function
local function ToggleRainRecursive(interval)
    wait(interval)
    if RainEnabled then
        RainEnabled = false
    elseif not RainEnabled then -- or else
        RainEnabled = true
    end

    ToggleRainRecursive(math.random(30,90)) -- range between 30 to 90 seconds
end

-- Creating a new thread
spawn(ToggleRainRecursive(math.random(30,90)))

-- SIDE NOTE: You need a function to toggle the rain first. lol
3 Likes

where do i put this. do i put it in the rain local script?

Be careful; this will eventually cause a stack overflow because Roblox Lua doesn’t have tail call optimisation! A better option is to use a loop:

local isRaining = false

spawn(function()
    while wait(math.random(60, 120)) do
        isRaining = not isRaining
        if isRaining then
            startRaining() 
        else
            stopRaining() 
        end
    end
end) 

This will toggle the rain periodically, waiting anywhere between 1-2 minutes (60-120 seconds), and call startRaining() and stopRaining() when the rain starts and stops. The current state is stored in isRaining.

6 Likes

It’s best to put this in a server script, that way it will rain for everyone at the same time.

i didn’t make the rain script credits go to this guy. boatbomber
i want it to rain at different times like jailbreak.

but where would i put the loop in this script.

--[[  ABOUT AND API INFO  -------------------------------------------------------------------------------------------------------------------------------------------------------------------
	
--- AUTHOR: Zack
---
--- CONTACT INFO: @BoatbomberRBLX on Twitter, boatbomber on Roblox
---
--- CREATION DATE: 12/10/2017
---
--- PURPOSE: Creates a realistic on-screen rain effect for games
---
--- SPECIAL NOTES:	Place inside a local domain. List of possible domains:
---					ReplicatedFirst, StarterGui, StarterPack, StarterPlayer.StarterPlayerScripts, or StarterPlayer.StarterCharacterScripts
---
--- GIT REPO: https://bitbucket.org/boatbomber/screenrain/src/master/
---
--- API:
---
--- 	Settings:
---
--- 		Distortion:
--- 			Description: 		Toggles if the rain droplets are made of glass, causing realistic "water" distortion. If false, uses ImageLabels instead.
---				Type: 				Boolean
--- 			Example: 			true
---
--- 		Rate:
--- 			Description: 		How many droplets spawn per second
---				Type: 				Number
--- 			Example: 			5
---			Size:
--- 			Description: 		How large the droplets are. If using GUIs, set in pixels; if using Distortion, set in studs.
---				Type: 				Number
--- 			Example: 			40 (for pixels) 0.3 (for studs)
---
--- 		SizeRandomness:
--- 			Description:		Toggles if the droplets are exactly sized, or can be a little off (for a more natural feeling)
---				Type: 				Boolean
--- 			Example: 			true
---
--- 			SizeRandomNoise:
--- 				Description: 	Sets how far off the size can be. If using GUIs, set in pixels; if using Distortion, set in studs. (Only matters if SizeRandomness is true)
---					Type: 			Number
--- 				Example: 		10 (for pixels) 0.1 (for studs)
---
--- 		Tint:
--- 			Description:		Toggles if the droplets are tinted. If false, it will be a realistic blue-ish clear
---				Type: 				Boolean
--- 			Example: 			false
---
--- 			TintColor:
--- 				Description:	Sets the color of the tint (Only matters if Tint is true)
---					Type:			Color3
--- 				Example:		Color3.fromRGB(117, 230, 255)
--- 
--- 		FadeSpeed:
--- 			Description:		How quickly the droplets fade away, in seconds.
---				Type:				Number
--- 			Example:			1
---
--- 		Sound:
--- 			Description:		Toggles dynamic sound. (Sound lowers when indoors, volume changes based on camera angle, etc.)
---				Type:				Boolean
--- 			Example:			true
---
--- 		Theme:
--- 			Description:		If Distortion is false, this can be set to "Preset" or "Custom" to either use the preset droplet images, or use your own.
---				Type:				String
--- 			Example:			"Preset"
---
--- 			Themes:
--- 				Description: 	Table with the Preset theme, and a place to create your Custom theme
---					Type:			Table
--- 				Example:		Preset = {1197357237, 1197356853, 1197357004, 1197356610, 1197356458, 1197357445, 1197357656, 1197358187, 1197358487, 1197357888};
--									Custom = {}
---
--- 		PhysicalRain:
--- 			Description:		Toggles part rain falling in the world around the player. (Done locally, so it doesn't lag nor affect other players)
---				Type:				Boolean
--- 			Example:			true
---
--- 			PhysicalRainWind:
--- 				Description: 	Adds a wind effect to the rain, in X and Z axis of world space. It's set by angles, so 50 is a strong wind, etc. (Only matters if PhysicalRain is true)
---					Type: 			Vector2
--- 				Example: 		Vector2.new(2,2)
---
--- 			PhysicalRainRadius:
--- 				Description: 	How far around the player the rain will fall. (Only matters if PhysicalRain is true)
---					Type: 			Number
--- 				Example: 		50
---
--- 			Gusts:		--[[DO NOT RECOMMEND USING YET. CAUSES MAJOR FRAME DROPS]]--
--- 				Description: 	Allows the wind to flare up for a moment, rather than only be constant.
---					Type: 			Boolean
--- 				Example: 		false
---
--- 				GustsPerMin:
--- 					Description: 	How many gusts will occur per minute, on average. (Only matters if Gusts is true)
---						Type: 			Number
--- 					Example: 		20
---
--- 				GustsStrength:
--- 					Description: 	How much extra wind a gust can add. (Only matters if Gusts is true)
---						Type: 			Number
--- 					Example: 		10
---
---]]
	
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
---		SETTINGS
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

local Settings = {
	
	Distortion		= true;
	
	Rate			= 7;
	
	Size			= 0.3;
	
	SizeRandomness	= true;
		SizeRandomNoise = 0.1;
		
	Tint			= false;
		TintColor				= Color3.fromRGB(111, 193, 255);
		
	FadeSpeed		= 1;
	
	Sound			= true;
	
	Theme			= "Preset";
		Themes					= {
					Preset = {1197357237, 1197356853, 1197357004, 1197356610, 1197356458, 1197357445, 1197357656, 1197358187, 1197358487, 1197357888};
					Custom = {} -- Insert your own AssetIDs
		};
		
	PhysicalRain	= true;
		PhysicalRainWind		= Vector2.new(2,2);
		PhysicalRainRadius		= 75;
		Gusts					= true;
			GustsPerMin				= 15;
			GustsStrength			= 10;


}

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
---		SERVICES
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

local ContentProvider	= game:GetService("ContentProvider")
local TweenService		= game:GetService("TweenService")
local UserInputService	= game:GetService("UserInputService")
local RunService		= game:GetService("RunService")

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
---		VARIABLES
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

	--[[ MATH ]]--
	
local instance										= Instance.new
local brickcolor, color3, colorsequence				= BrickColor.new, Color3.fromRGB, ColorSequence.new
local numbersequence, numberrange					= NumberSequence.new, NumberRange.new
local cf, v3, v2, udim2, newray						= CFrame.new, Vector3.new, Vector2.new, UDim2.new, Ray.new
local pow, sin, cos, pi, sqrt, abs, asin, random	= math.pow, math.sin, math.cos, math.pi, math.sqrt, math.abs, math.asin, math.random

	--[[CLIENT]]--
	
local Camera			= workspace.CurrentCamera 
local player			= game.Players.LocalPlayer

	--[[ SCRIPT ]]--
	local RainEnabled = false

-- The function
local function ToggleRainRecursive(interval)
    wait(interval)
    if RainEnabled then
	local Distortion		= Settings.Distortion	
local Rate				= Settings.Rate
local Size				= Settings.Size
local SizeRandomness	= Settings.SizeRandomness
local SizeRandomNoise	= Settings.SizeRandomNoise
local Tint				= Settings.Tint
local TintColor			= Settings.TintColor
local FadeSpeed			= Settings.FadeSpeed
local Sound				= Settings.Sound
local ChosenTheme		= Settings.Theme
local Theme				= Settings.Themes[ChosenTheme]
local PhysicalRain		= Settings.PhysicalRain
local PhysicalRainWind	= Settings.PhysicalRainWind
local PhysicalRainRadius= Settings.PhysicalRainRadius
local Gusts				= Settings.Gusts
local GustsPerMin		= Settings.GustsPerMin
local GustsStrength		= Settings.GustsStrength

local Gusting			= true
local LastGust			= tick()

local mainGUI
local RainSound			= instance("Sound")
	RainSound.SoundId	= "rbxassetid://2027808328"
	RainSound.Looped	= true

local PartNum = 1

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
---		SETUP
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

	--[[MATH]]--
	
math.randomseed(tick())

	--[[ASSETS]]--
	
if not Distortion then
	local Assets = {true}
	for i=1, #Theme do
		Assets[i] = ("rbxassetid://" .. Theme[i])
	end
	ContentProvider:PreloadAsync(Assets)
	wait()
	while ContentProvider.RequestQueueSize > 0 do
		print("Waiting for images to load...")
		wait()
	end
end

	--[[SCRIPT]]--
	
if Sound then
	RainSound.Parent = Camera
	RainSound:Play()
end

if not Distortion then
	mainGUI = instance('ScreenGui')
		mainGUI.Name = 'RainGUI'
		mainGUI.Parent = player.PlayerGui
end


	--[[ROBLOX CLIENT]]--
	
UserInputService.MouseIconEnabled = true

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
---		FUNCTIONS
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

local function weldBetween(a, b)
	local weld	= Instance.new("Weld")
		weld.C0 = a.CFrame:inverse() * b.CFrame
		
		weld.Part0 = a
		weld.Part1 = b
	weld.Parent = a
	
	return weld
end

local function BoxPos(Origin, Radius)
	return cf(Origin +v3(random(-Radius, Radius), 50, random(-Radius, Radius)))
end

local function inSine(t, b, c, d)
	return -c * cos(t / d * (pi / 2)) + c + b
end

local function CreateSplash(Position)
	local Part = instance("Part")
		Part.Anchored		= true
		Part.CanCollide		= false
		Part.Transparency	= 1
		Part.Position		= Position - v3(0,0.5,0)
		Part.Name 			= 'SplashPart'
		Part.Size			= v3(1,1,1)
		
	local splashParticles = instance('ParticleEmitter')
		if Tint then
			splashParticles.Color 			= TintColor
		else
			splashParticles.Color 			= colorsequence(color3(187,234,255))
		end
		splashParticles.Size			= numbersequence(0,1.3)
		splashParticles.Texture 		= 'rbxassetid://241576804'
		splashParticles.Acceleration 	= v3(0,-30,0)
		splashParticles.Rotation		= numberrange(0,360)
		splashParticles.Lifetime 		= numberrange(0.4)
		splashParticles.Rate 			= 2
		splashParticles.Speed 			= numberrange(3)
	splashParticles.Parent			= Part
		
	Part.Parent = Camera
	delay(1, function()
		Part:Destroy()
	end)
end

local function CreatePhysicalRain(OriginPoint)
	--Create
	local Part	= instance("Part")
		Part.Name 			= 'RainPart'
		Part.TopSurface		= Enum.SurfaceType.Smooth
		Part.BottomSurface	= Enum.SurfaceType.Smooth
		Part.CanCollide		= false
		Part.Size			= Vector3.new(0.05, 2.5, 0.05)
		Part.Material		= Enum.Material.SmoothPlastic
		if Tint then
			Part.Color = TintColor
		else
			Part.Color = color3(169, 228, 255)
		end
	
		Part.CFrame			= BoxPos(OriginPoint, PhysicalRainRadius)
		Part.Orientation	= Vector3.new(PhysicalRainWind.X + random(-3,3), 0, PhysicalRainWind.Y + random(-3,3))
	
	local V		= instance('BodyVelocity')
		V.Velocity			= Part.CFrame.upVector * -150
		V.MaxForce			= v3(5000,5000,5000)
	V.Parent = Part
	
	Part.Touched:Connect(function(hit)
		if not hit:IsDescendantOf(player.Character) and not hit:IsDescendantOf(Camera) then
			CreateSplash(Part.Position);
		end
		Part:Destroy()
	end)
	
	Part.Parent = workspace.CurrentCamera
	
	
end

local function createDistortionDroplet()
	local glass			= instance('Part')
		glass.CanCollide	= false
		glass.Material 		= 'Glass'
		glass.Name 			= 'Droplet_Main'
		glass.Transparency 	= 0.6
		glass.Shape 		= 'Ball'
	
	if Tint then
		glass.Color = TintColor
	else
		glass.Color = color3(200,200,220)
	end
	
	if SizeRandomness then
		local x 	= random(-SizeRandomNoise*10, SizeRandomNoise*10)/10
		glass.Size 	= v3(Size+x, Size+x, Size+x)
	else
		glass.Size 	= v3(Size, Size, Size)
	end
	
	local objectSpace = cf(random(-450,450)/100, random(-300,300)/100, -4)
	local function MoveDroplet()
		local screenSpace = Camera.CFrame:toWorldSpace(objectSpace)
		glass.CFrame = screenSpace
	end
	
	RunService:BindToRenderStep("DropletUpdate", Enum.RenderPriority.Camera.Value + 1, MoveDroplet)
	
	local tweens = {}
	local goal = {}
		goal.Transparency = 1
		local tweenInfo = TweenInfo.new(FadeSpeed+0.2, Enum.EasingStyle.Sine,  Enum.EasingDirection.In) 
		local tween = TweenService:Create(glass, tweenInfo, goal)
	
	glass.Parent = Camera
	
	tweens[#tweens+1] = tween
	for i=1, random(1,4) do
		local p2 = instance('Part')
		p2.CanCollide = false
		p2.Material = 'Glass'
		p2.Transparency = 0.6
		p2.Shape = 'Ball'
		p2.Name = 'Inner_Part'
		if Tint then
			p2.Color = TintColor
		else
			p2.Color = color3(200,200,220)
		end
		local v = random(-SizeRandomNoise*100, SizeRandomNoise*100)/100
		p2.Size = glass.Size+v3(v,v,v)
		p2.Parent = glass
		p2.CFrame = glass.CFrame+v3(random(-12,12)/100,random(-12,12)/100,0)
		weldBetween(p2, glass)
		local tween = TweenService:Create(p2, tweenInfo, goal)
		tweens[#tweens+1] = tween
		delay(FadeSpeed+0.2, function() p2:Destroy() end)
	end
	for i, t in pairs(tweens) do
		t:Play()
	end
	delay(FadeSpeed+0.2, function() glass:Destroy() end)
end

local function createDroplet()

	local n = random(1, #Theme)
	local Gui = instance("ImageLabel")
		Gui.AnchorPoint = v2(0.5,0.5)
		Gui.BackgroundTransparency = 1
		Gui.Position = udim2( (random(0,100)/100), 0, (random(0,100)/100), 0 )
		Gui.Rotation = random(0,360)
		Gui.Image = ("rbxassetid://"..Theme[n])
		if SizeRandomness then
			local x = random(-SizeRandomNoise, SizeRandomNoise)
			Gui.Size = udim2(
				0,
				Size+x,
				0,
				Size+x)
		else
			Gui.Size = udim2(0, Size, 0, Size)
		end
		if Tint then
			Gui.ImageColor3 = TintColor
		end
		Gui.Parent = mainGUI
		local goal = {}
			goal.ImageTransparency = 1
		local tweenInfo = TweenInfo.new(FadeSpeed+0.2, Enum.EasingStyle.Sine,  Enum.EasingDirection.In) 
		local tween = TweenService:Create(Gui, tweenInfo, goal)
		tween:Play()
		delay(FadeSpeed+0.2, function() Gui:Destroy() end)
end

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
---		LOOP
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

while wait(1/Rate) do
	if PhysicalRain then
		local dropRain		= coroutine.wrap(function()
			for i=1, Rate*5 do
				CreatePhysicalRain(Camera.CFrame.p)
			end
		end)
		dropRain()
	end
	
	if Gusts and not Gusting and tick()-LastGust > (60/GustsPerMin) and random()>0.5 then
		Gusting				= true
		LastGust			= tick()
		local strength		= random(2,GustsStrength)
		local gustLength	= random(4,10)
		local begin			= v2(Settings.PhysicalRainWind.X, Settings.PhysicalRainWind.Y)
		local ending		= v2(Settings.PhysicalRainWind.X+strength, Settings.PhysicalRainWind.Y+strength)
		local Schange		= ending-begin
		local Echange		= begin-ending
		
		local blowGust		= coroutine.wrap(function()
			for i=1, 20 do
				wait(gustLength/20)
				PhysicalRainWind = v2(
					inSine(gustLength, begin.X, Schange.X, i/20),
					inSine(gustLength, begin.Y, Schange.Y, i/20)
					)
			end
			wait(0.1)
			for i=1, 20 do
				wait(gustLength/20)
				PhysicalRainWind = v2(
					inSine(gustLength, ending.X, (Echange.X), i/20),
					inSine(gustLength, ending.Y, (Echange.Y), i/20)
					)
			end
			Gusting			= false
		end)
		
		blowGust()
	end

	local ray					= newray(Camera.CFrame.p, Camera.CFrame.p+v3(0,3,0) * 70) 
 	local hit, position, normal = workspace:FindPartOnRay(ray, player.Character)

	if hit and hit.Transparency ~=1 and not hit:IsDescendantOf(Camera) then
		if Sound and RainSound.Volume ~= 0.7 then
			RainSound.Volume = 0.7
		end
		
	elseif not hit then
		if Sound and RainSound.Volume ~= 2 then
			RainSound.Volume = 2
		end
		if Camera.CFrame.lookVector.Y>-0.1	then
			if Distortion then
				createDistortionDroplet()
			else
				createDroplet()
			end
		end
	end
end
        RainEnabled = false
    elseif not RainEnabled then -- or else
        RainEnabled = true
    end

    ToggleRainRecursive(math.random(30,90)) -- range between 30 to 90 seconds
end

-- Creating a new thread
spawn(ToggleRainRecursive(math.random(30,90)))

-- SIDE NOTE: You need a function to toggle the rain first. lol
local Distortion		= Settings.Distortion	
local Rate				= Settings.Rate
local Size				= Settings.Size
local SizeRandomness	= Settings.SizeRandomness
local SizeRandomNoise	= Settings.SizeRandomNoise
local Tint				= Settings.Tint
local TintColor			= Settings.TintColor
local FadeSpeed			= Settings.FadeSpeed
local Sound				= Settings.Sound
local ChosenTheme		= Settings.Theme
local Theme				= Settings.Themes[ChosenTheme]
local PhysicalRain		= Settings.PhysicalRain
local PhysicalRainWind	= Settings.PhysicalRainWind
local PhysicalRainRadius= Settings.PhysicalRainRadius
local Gusts				= Settings.Gusts
local GustsPerMin		= Settings.GustsPerMin
local GustsStrength		= Settings.GustsStrength

local Gusting			= true
local LastGust			= tick()

local mainGUI
local RainSound			= instance("Sound")
	RainSound.SoundId	= "rbxassetid://2027808328"
	RainSound.Looped	= true

local PartNum = 1

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
---		SETUP
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

	--[[MATH]]--
	
math.randomseed(tick())

	--[[ASSETS]]--
	
if not Distortion then
	local Assets = {true}
	for i=1, #Theme do
		Assets[i] = ("rbxassetid://" .. Theme[i])
	end
	ContentProvider:PreloadAsync(Assets)
	wait()
	while ContentProvider.RequestQueueSize > 0 do
		print("Waiting for images to load...")
		wait()
	end
end

	--[[SCRIPT]]--
	
if Sound then
	RainSound.Parent = Camera
	RainSound:Play()
end

if not Distortion then
	mainGUI = instance('ScreenGui')
		mainGUI.Name = 'RainGUI'
		mainGUI.Parent = player.PlayerGui
end


	--[[ROBLOX CLIENT]]--
	
UserInputService.MouseIconEnabled = true

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
---		FUNCTIONS
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

local function weldBetween(a, b)
	local weld	= Instance.new("Weld")
		weld.C0 = a.CFrame:inverse() * b.CFrame
		
		weld.Part0 = a
		weld.Part1 = b
	weld.Parent = a
	
	return weld
end

local function BoxPos(Origin, Radius)
	return cf(Origin +v3(random(-Radius, Radius), 50, random(-Radius, Radius)))
end

local function inSine(t, b, c, d)
	return -c * cos(t / d * (pi / 2)) + c + b
end

local function CreateSplash(Position)
	local Part = instance("Part")
		Part.Anchored		= true
		Part.CanCollide		= false
		Part.Transparency	= 1
		Part.Position		= Position - v3(0,0.5,0)
		Part.Name 			= 'SplashPart'
		Part.Size			= v3(1,1,1)
		
	local splashParticles = instance('ParticleEmitter')
		if Tint then
			splashParticles.Color 			= TintColor
		else
			splashParticles.Color 			= colorsequence(color3(187,234,255))
		end
		splashParticles.Size			= numbersequence(0,1.3)
		splashParticles.Texture 		= 'rbxassetid://241576804'
		splashParticles.Acceleration 	= v3(0,-30,0)
		splashParticles.Rotation		= numberrange(0,360)
		splashParticles.Lifetime 		= numberrange(0.4)
		splashParticles.Rate 			= 2
		splashParticles.Speed 			= numberrange(3)
	splashParticles.Parent			= Part
		
	Part.Parent = Camera
	delay(1, function()
		Part:Destroy()
	end)
end

local function CreatePhysicalRain(OriginPoint)
	--Create
	local Part	= instance("Part")
		Part.Name 			= 'RainPart'
		Part.TopSurface		= Enum.SurfaceType.Smooth
		Part.BottomSurface	= Enum.SurfaceType.Smooth
		Part.CanCollide		= false
		Part.Size			= Vector3.new(0.05, 2.5, 0.05)
		Part.Material		= Enum.Material.SmoothPlastic
		if Tint then
			Part.Color = TintColor
		else
			Part.Color = color3(169, 228, 255)
		end
	
		Part.CFrame			= BoxPos(OriginPoint, PhysicalRainRadius)
		Part.Orientation	= Vector3.new(PhysicalRainWind.X + random(-3,3), 0, PhysicalRainWind.Y + random(-3,3))
	
	local V		= instance('BodyVelocity')
		V.Velocity			= Part.CFrame.upVector * -150
		V.MaxForce			= v3(5000,5000,5000)
	V.Parent = Part
	
	Part.Touched:Connect(function(hit)
		if not hit:IsDescendantOf(player.Character) and not hit:IsDescendantOf(Camera) then
			CreateSplash(Part.Position);
		end
		Part:Destroy()
	end)
	
	Part.Parent = workspace.CurrentCamera
	
	
end

local function createDistortionDroplet()
	local glass			= instance('Part')
		glass.CanCollide	= false
		glass.Material 		= 'Glass'
		glass.Name 			= 'Droplet_Main'
		glass.Transparency 	= 0.6
		glass.Shape 		= 'Ball'
	
	if Tint then
		glass.Color = TintColor
	else
		glass.Color = color3(200,200,220)
	end
	
	if SizeRandomness then
		local x 	= random(-SizeRandomNoise*10, SizeRandomNoise*10)/10
		glass.Size 	= v3(Size+x, Size+x, Size+x)
	else
		glass.Size 	= v3(Size, Size, Size)
	end
	
	local objectSpace = cf(random(-450,450)/100, random(-300,300)/100, -4)
	local function MoveDroplet()
		local screenSpace = Camera.CFrame:toWorldSpace(objectSpace)
		glass.CFrame = screenSpace
	end
	
	RunService:BindToRenderStep("DropletUpdate", Enum.RenderPriority.Camera.Value + 1, MoveDroplet)
	
	local tweens = {}
	local goal = {}
		goal.Transparency = 1
		local tweenInfo = TweenInfo.new(FadeSpeed+0.2, Enum.EasingStyle.Sine,  Enum.EasingDirection.In) 
		local tween = TweenService:Create(glass, tweenInfo, goal)
	
	glass.Parent = Camera
	
	tweens[#tweens+1] = tween
	for i=1, random(1,4) do
		local p2 = instance('Part')
		p2.CanCollide = false
		p2.Material = 'Glass'
		p2.Transparency = 0.6
		p2.Shape = 'Ball'
		p2.Name = 'Inner_Part'
		if Tint then
			p2.Color = TintColor
		else
			p2.Color = color3(200,200,220)
		end
		local v = random(-SizeRandomNoise*100, SizeRandomNoise*100)/100
		p2.Size = glass.Size+v3(v,v,v)
		p2.Parent = glass
		p2.CFrame = glass.CFrame+v3(random(-12,12)/100,random(-12,12)/100,0)
		weldBetween(p2, glass)
		local tween = TweenService:Create(p2, tweenInfo, goal)
		tweens[#tweens+1] = tween
		delay(FadeSpeed+0.2, function() p2:Destroy() end)
	end
	for i, t in pairs(tweens) do
		t:Play()
	end
	delay(FadeSpeed+0.2, function() glass:Destroy() end)
end

local function createDroplet()

	local n = random(1, #Theme)
	local Gui = instance("ImageLabel")
		Gui.AnchorPoint = v2(0.5,0.5)
		Gui.BackgroundTransparency = 1
		Gui.Position = udim2( (random(0,100)/100), 0, (random(0,100)/100), 0 )
		Gui.Rotation = random(0,360)
		Gui.Image = ("rbxassetid://"..Theme[n])
		if SizeRandomness then
			local x = random(-SizeRandomNoise, SizeRandomNoise)
			Gui.Size = udim2(
				0,
				Size+x,
				0,
				Size+x)
		else
			Gui.Size = udim2(0, Size, 0, Size)
		end
		if Tint then
			Gui.ImageColor3 = TintColor
		end
		Gui.Parent = mainGUI
		local goal = {}
			goal.ImageTransparency = 1
		local tweenInfo = TweenInfo.new(FadeSpeed+0.2, Enum.EasingStyle.Sine,  Enum.EasingDirection.In) 
		local tween = TweenService:Create(Gui, tweenInfo, goal)
		tween:Play()
		delay(FadeSpeed+0.2, function() Gui:Destroy() end)
end

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
---		LOOP
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

while wait(1/Rate) do
	if PhysicalRain then
		local dropRain		= coroutine.wrap(function()
			for i=1, Rate*5 do
				CreatePhysicalRain(Camera.CFrame.p)
			end
		end)
		dropRain()
	end
	
	if Gusts and not Gusting and tick()-LastGust > (60/GustsPerMin) and random()>0.5 then
		Gusting				= true
		LastGust			= tick()
		local strength		= random(2,GustsStrength)
		local gustLength	= random(4,10)
		local begin			= v2(Settings.PhysicalRainWind.X, Settings.PhysicalRainWind.Y)
		local ending		= v2(Settings.PhysicalRainWind.X+strength, Settings.PhysicalRainWind.Y+strength)
		local Schange		= ending-begin
		local Echange		= begin-ending
		
		local blowGust		= coroutine.wrap(function()
			for i=1, 20 do
				wait(gustLength/20)
				PhysicalRainWind = v2(
					inSine(gustLength, begin.X, Schange.X, i/20),
					inSine(gustLength, begin.Y, Schange.Y, i/20)
					)
			end
			wait(0.1)
			for i=1, 20 do
				wait(gustLength/20)
				PhysicalRainWind = v2(
					inSine(gustLength, ending.X, (Echange.X), i/20),
					inSine(gustLength, ending.Y, (Echange.Y), i/20)
					)
			end
			Gusting			= false
		end)
		
		blowGust()
	end

	local ray					= newray(Camera.CFrame.p, Camera.CFrame.p+v3(0,3,0) * 70) 
 	local hit, position, normal = workspace:FindPartOnRay(ray, player.Character)

	if hit and hit.Transparency ~=1 and not hit:IsDescendantOf(Camera) then
		if Sound and RainSound.Volume ~= 0.7 then
			RainSound.Volume = 0.7
		end
		
	elseif not hit then
		if Sound and RainSound.Volume ~= 2 then
			RainSound.Volume = 2
		end
		if Camera.CFrame.lookVector.Y>-0.1	then
			if Distortion then
				createDistortionDroplet()
			else
				createDroplet()
			end
		end
	end
end`

sorry if thats a hassle to read i did not make this but i just wanted to know how to make it rain at different time like jailbreak. sorry if that code is too much. most likely it is.

3 Likes

Don’t use recursion for that, it’s not necessary and will break.

1 Like

Can you fix the video? I can’t see it, all it says is “No video with supported format and MIME type found.”

Fir the final while loop, wrap the second layer in a if statement.

while wait(1/rate) do
  if rain then
       --Rest of code
  end
end
--rain is a bool, when set to true it will rain.

For my weather system I have a similar function for rain as above but inside the loop I put another if statement with math.random so it isn’t guaranteed to run every iteration. The rain is created locally on the client and a remote event is sent to all clients to start and stop the rain. There is also a bool value in the workspace which is set to true if it’s raining, then when a player respawns it checks to see if that value is true and restarts the rain on their client if the value is true. I don’t know if that is the best way but that’s the way I do it. If you want to see any of my code I can show you. I hope that was somewhat helpful.

1 Like

But you wan’t Random Rain? Or specific Time Rain?
Because it changes the configuration Your preference, if it is random or at a specific time, if it is predetermined You will have to make a variable for it, If you do not make a variable this will not stop it from raining (From generating the model)

You could just use TweenService.
TweenTime is how long the tween takes. Brightness is how bright it should be.

game:GetService("TweenService"):Create(game.Lighting, TweenInfo.new(TweenTime), {Brightness = 1}):Play()

someone names buildthomas edited it or something, ill fix it

I want random rain not set so it rains randomly from time to time.

can I see some of your code yes this is helpful you explained it in a way a small starter dev like me can understand.

You want to edit the loop section, this is where the rain takes place
You want the loop to go for a while then end
Here is an example

--This is for the loop section     
local raintime = 0 -- ADD THIS
while true do 
raintime = 0
wait(math.random(120,160) --However long you want here just make sure it is longer than the amount of time it rains

while wait(1/Rate) and raintime < math.random(70,80) do --you want to add the {raintime < math.random(70,80)} you can change the time if you would like to
  raintime = raintime + (1/Rate) --This is to add to the amount of time varible
    if PhysicalRain then --back to normal script
    	local dropRain		= coroutine.wrap(function()
    		for i=1, Rate*5 do
    			CreatePhysicalRain(Camera.CFrame.p)
    		end
    	end)
    	dropRain()
	end	

--The rest of the code inside

end
 --ADD END HERE for the added while true do
end

Pretty much how this code works is, that it will be in a forever loop
It will wait for the amount of time it needs until it starts to rain
Then the rain code will go through
Then it will end and the cycle continues

1 Like