In short
In a Script in ServerScriptService, pick a weather (Clear, Rain or Storm) every few minutes and store it with workspace:SetAttribute("Weather", "Rain"). In a LocalScript in StarterPlayerScripts, listen to workspace:GetAttributeChangedSignal("Weather"). Make an invisible, anchored part with a ParticleEmitter pointing down, move it above the camera every frame, and turn its Rate up when it rains. Tween the Atmosphere in Lighting to more Density and Haze for fog, and play a looped rain Sound.
- Rain is only visuals, so it is drawn on each client. The server sends one word, which keeps the game fast.
- Move the rain with the camera instead of covering the whole map: a few hundred particles near the player look like a downpour everywhere.
- Cast a ray up from the camera to find roofs, and turn the rain off while there is one.
Get the script
Rain and weather script (client)
A LocalScript that draws the weather the server picks: rain particles around the camera that stop indoors, fog, a rain sound and thunder flashes.
-- LocalScript in StarterPlayerScripts named WeatherClient.
-- Draws the weather the server picked: rain, fog, light, sound and thunder.
local Lighting = game:GetService("Lighting")
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local SoundService = game:GetService("SoundService")
local TweenService = game:GetService("TweenService")
local RAIN_RATE = 500 -- raindrops per second in Rain; Storm doubles it
local RAIN_HEIGHT = 40 -- studs above the camera where drops start
local RAIN_AREA = 90 -- width of the rain box around the camera, in studs
local FADE_SECONDS = 6 -- how long fog and light take to change
local RAIN_SOUND_ID = "" -- a looping rain sound, for example "rbxassetid://123456"
local THUNDER_SOUND_ID = "" -- a thunder clap
local RAIN_TEXTURE = "" -- a raindrop image; empty keeps the default particle
local player = Players.LocalPlayer
-- The Atmosphere gives fog and haze. Use the place's own, or add one.
local atmosphere = Lighting:FindFirstChildOfClass("Atmosphere")
if not atmosphere then
local created = Instance.new("Atmosphere")
created.Parent = Lighting
atmosphere = created
end
local fog = atmosphere :: Atmosphere
-- Clear weather is whatever the place already looks like
type Look = { density: number, haze: number, color: Color3, brightness: number }
local clear: Look = { density = fog.Density, haze = fog.Haze, color = fog.Color, brightness = Lighting.Brightness }
local LOOKS: { [string]: Look } = {
Clear = clear,
Rain = { density = 0.45, haze = 2, color = Color3.fromRGB(150, 156, 168), brightness = clear.brightness * 0.6 },
Storm = { density = 0.55, haze = 3, color = Color3.fromRGB(105, 110, 122), brightness = clear.brightness * 0.35 },
}
-- An invisible box above the camera that rain falls out of. Only this client has it.
local rainBox = Instance.new("Part")
rainBox.Name = "RainBox"
rainBox.Anchored = true
rainBox.CanCollide = false
rainBox.CanTouch = false
rainBox.CanQuery = false
rainBox.Transparency = 1
rainBox.Size = Vector3.new(RAIN_AREA, 1, RAIN_AREA)
rainBox.Parent = workspace
local emitter = Instance.new("ParticleEmitter")
emitter.Shape = Enum.ParticleEmitterShape.Box
emitter.ShapeStyle = Enum.ParticleEmitterShapeStyle.Volume -- drops start anywhere inside the box
emitter.EmissionDirection = Enum.NormalId.Bottom
emitter.Speed = NumberRange.new(70, 85)
emitter.Lifetime = NumberRange.new(0.8, 1)
emitter.Orientation = Enum.ParticleOrientation.VelocityParallel -- stretch along the fall
emitter.Squash = NumberSequence.new(2) -- above 0: thinner and taller, a streak
emitter.Size = NumberSequence.new(0.15)
emitter.Transparency = NumberSequence.new(0.4)
emitter.Color = ColorSequence.new(Color3.fromRGB(200, 210, 225))
emitter.LightInfluence = 1
emitter.Rate = 0
if RAIN_TEXTURE ~= "" then
emitter.Texture = RAIN_TEXTURE
end
emitter.Parent = rainBox
local rainSound = Instance.new("Sound")
rainSound.Name = "RainLoop"
rainSound.Looped = true
rainSound.Volume = 0
rainSound.SoundId = RAIN_SOUND_ID
rainSound.Parent = SoundService
local currentRate = 0 -- the rate for this weather, before the roof check
local indoors = false
local fadeInfo = TweenInfo.new(FADE_SECONDS, Enum.EasingStyle.Sine)
local function applyWeather()
local name = workspace:GetAttribute("Weather")
local look = if type(name) == "string" and LOOKS[name] then LOOKS[name] else clear
TweenService:Create(fog, fadeInfo, { Density = look.density, Haze = look.haze, Color = look.color }):Play()
TweenService:Create(Lighting, fadeInfo, { Brightness = look.brightness }):Play()
currentRate = if name == "Storm" then RAIN_RATE * 2 elseif name == "Rain" then RAIN_RATE else 0
local volume = if name == "Storm" then 0.8 elseif name == "Rain" then 0.5 else 0
if volume > 0 and RAIN_SOUND_ID ~= "" and not rainSound.IsPlaying then
rainSound:Play()
end
TweenService:Create(rainSound, fadeInfo, { Volume = volume }):Play()
end
-- Thunder: a quick flash, then the rumble a moment later (sound travels slower than light)
local function onThunder()
if workspace:GetAttribute("Weather") ~= "Storm" then
return
end
local flashUp = TweenService:Create(Lighting, TweenInfo.new(0.08), { ExposureCompensation = 1.5 })
local flashDown = TweenService:Create(Lighting, TweenInfo.new(0.5), { ExposureCompensation = 0 })
flashUp:Play()
flashUp.Completed:Once(function()
flashDown:Play()
end)
if THUNDER_SOUND_ID ~= "" then
task.delay(0.4 + math.random() * 1.2, function()
local thunder = Instance.new("Sound")
thunder.SoundId = THUNDER_SOUND_ID
thunder.Volume = 0.8
thunder.Parent = SoundService
thunder:Play()
thunder.Ended:Once(function()
thunder:Destroy()
end)
end)
end
end
workspace:GetAttributeChangedSignal("Weather"):Connect(applyWeather)
workspace:GetAttributeChangedSignal("ThunderAt"):Connect(onThunder)
applyWeather()
-- Every frame: keep the rain box above the camera. A few times a second: check for a roof.
local roofParams = RaycastParams.new()
local sinceRoofCheck = 0
RunService.RenderStepped:Connect(function(deltaTime: number)
local camera = workspace.CurrentCamera
local position = camera.CFrame.Position
rainBox.CFrame = CFrame.new(position + Vector3.new(0, RAIN_HEIGHT, 0))
sinceRoofCheck += deltaTime
if sinceRoofCheck >= 0.2 then
sinceRoofCheck = 0
local character = player.Character
roofParams.ExcludeInstances = if character then { character } else {}
-- Anything solid above the camera counts as a roof
indoors = workspace:Raycast(position, Vector3.new(0, RAIN_HEIGHT + 60, 0), roofParams) ~= nil
end
emitter.Rate = if indoors then 0 else currentRate
-- Rain sounds muffled indoors instead of stopping
rainSound.PlaybackSpeed = if indoors then 0.85 else 1
end)
RoCode builds it in the place you have open in Roblox Studio, on Windows or macOS with a desktop browser; on a phone the button sends the prompt and the link to your computer. Free to start, with free credits every day. More Roblox Studio scripts
Where to put it
ServerScriptService
WeatherService Script new
StarterPlayer
StarterPlayerScripts
WeatherClient LocalScript new
Settings you can change
RAIN_RATEIn the script- Raindrops per second around the camera in Rain. Storm doubles it. Lower it if phones slow down. Default:
500. RAIN_SOUND_IDIn the script- The rain loop's audio ID from the Toolbox, such as
"rbxassetid://123". Leave it empty for no sound. RAIN_TEXTUREIn the script- An image ID for a raindrop. Empty keeps Roblox's default particle texture, which the script stretches into streaks.
Needs the WeatherService Script from Step 1, which sets the Weather and ThunderAt attributes on the Workspace.
Type-checked with luau-lsp strict against Roblox's API definitions on 14 November 2026. Not playtested in Studio yet: press Play and watch the Output window before you publish.
Prompt for RoCode
Add a weather system to my game: a Script in ServerScriptService that picks Clear, Rain or Storm by weight every few minutes, stores it in a Weather attribute on the Workspace and sets a ThunderAt attribute for lightning during storms, and a LocalScript in StarterPlayerScripts that draws rain with a ParticleEmitter in a part that follows the camera, turns the rain off under roofs with an upward raycast, tweens the Atmosphere and Lighting darker, loops a rain sound and flashes the screen on thunder.
On this page
How the weather system works
| Part | Runs on | Job |
|---|---|---|
| WeatherService | Server | Picks the next weather and how long it lasts. Sets the Weather attribute on the Workspace, and the ThunderAt attribute for each lightning strike. |
| Workspace attributes | Both | Copied from the server to every player, including players who join later. |
| WeatherClient | Each client | Draws rain, fades fog and light, plays the rain sound and the thunder flash. |
Why not make the rain on the server? Thousands of raindrops would have to be sent to every player, and the server would be busy with something nobody can play with. An attribute is one short string. Each device then draws as much rain as it can handle, right where its own camera is.
The weather changes slowly, so the client tweens the fog and light over a few seconds when the attribute changes. Clear weather uses the values your place already has, so the system never fights your own lighting setup.
Step 1: The server picks the weather
- Hover over ServerScriptService, click + and insert a Script named
WeatherService. - Paste the code below.
-- Script in ServerScriptService named WeatherService.
-- Picks the weather and tells every client through attributes on the Workspace.
type Weather = { name: string, weight: number, minSeconds: number, maxSeconds: number }
-- weight: how often it is picked compared with the others
local WEATHERS: { Weather } = {
{ name = "Clear", weight = 5, minSeconds = 180, maxSeconds = 300 },
{ name = "Rain", weight = 3, minSeconds = 90, maxSeconds = 180 },
{ name = "Storm", weight = 1, minSeconds = 60, maxSeconds = 120 },
}
local THUNDER_MIN_GAP = 6 -- seconds between lightning strikes in a storm
local THUNDER_MAX_GAP = 20
local function pickNext(current: string?): Weather
-- Weighted random choice, never the same weather twice in a row
local total = 0
for _, weather in WEATHERS do
if weather.name ~= current then
total += weather.weight
end
end
local roll = math.random() * total
for _, weather in WEATHERS do
if weather.name ~= current then
roll -= weather.weight
if roll <= 0 then
return weather
end
end
end
return WEATHERS[1]
end
local current: string? = nil
workspace:SetAttribute("Weather", "Clear")
while true do
local weather = pickNext(current)
current = weather.name
workspace:SetAttribute("Weather", weather.name)
local duration = math.random(weather.minSeconds, weather.maxSeconds)
local endTime = os.clock() + duration
if weather.name == "Storm" then
-- Lightning: a new time stamp in ThunderAt is each client's cue to flash and rumble
while os.clock() < endTime do
task.wait(math.random(THUNDER_MIN_GAP, THUNDER_MAX_GAP))
if os.clock() < endTime and workspace:GetAttribute("Weather") == "Storm" then
workspace:SetAttribute("ThunderAt", workspace:GetServerTimeNow())
end
end
else
task.wait(duration)
end
end
The weights decide the mix: Clear is picked 5 times for every 3 Rains and 1 Storm, and the same weather never comes twice in a row. Each lightning strike sets ThunderAt to the server's clock. The value itself does not matter much; what matters is that it changes, because every client listens for that change.
Step 2: Draw the weather on each client
- Open StarterPlayer, hover over StarterPlayerScripts and insert a LocalScript named
WeatherClient. - Paste the code below.
- Optional: find a looping rain sound and a thunder sound in the Toolbox (Audio) and paste their IDs into
RAIN_SOUND_IDandTHUNDER_SOUND_ID, for example"rbxassetid://123456".
-- LocalScript in StarterPlayerScripts named WeatherClient.
-- Draws the weather the server picked: rain, fog, light, sound and thunder.
local Lighting = game:GetService("Lighting")
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local SoundService = game:GetService("SoundService")
local TweenService = game:GetService("TweenService")
local RAIN_RATE = 500 -- raindrops per second in Rain; Storm doubles it
local RAIN_HEIGHT = 40 -- studs above the camera where drops start
local RAIN_AREA = 90 -- width of the rain box around the camera, in studs
local FADE_SECONDS = 6 -- how long fog and light take to change
local RAIN_SOUND_ID = "" -- a looping rain sound, for example "rbxassetid://123456"
local THUNDER_SOUND_ID = "" -- a thunder clap
local RAIN_TEXTURE = "" -- a raindrop image; empty keeps the default particle
local player = Players.LocalPlayer
-- The Atmosphere gives fog and haze. Use the place's own, or add one.
local atmosphere = Lighting:FindFirstChildOfClass("Atmosphere")
if not atmosphere then
local created = Instance.new("Atmosphere")
created.Parent = Lighting
atmosphere = created
end
local fog = atmosphere :: Atmosphere
-- Clear weather is whatever the place already looks like
type Look = { density: number, haze: number, color: Color3, brightness: number }
local clear: Look = { density = fog.Density, haze = fog.Haze, color = fog.Color, brightness = Lighting.Brightness }
local LOOKS: { [string]: Look } = {
Clear = clear,
Rain = { density = 0.45, haze = 2, color = Color3.fromRGB(150, 156, 168), brightness = clear.brightness * 0.6 },
Storm = { density = 0.55, haze = 3, color = Color3.fromRGB(105, 110, 122), brightness = clear.brightness * 0.35 },
}
-- An invisible box above the camera that rain falls out of. Only this client has it.
local rainBox = Instance.new("Part")
rainBox.Name = "RainBox"
rainBox.Anchored = true
rainBox.CanCollide = false
rainBox.CanTouch = false
rainBox.CanQuery = false
rainBox.Transparency = 1
rainBox.Size = Vector3.new(RAIN_AREA, 1, RAIN_AREA)
rainBox.Parent = workspace
local emitter = Instance.new("ParticleEmitter")
emitter.Shape = Enum.ParticleEmitterShape.Box
emitter.ShapeStyle = Enum.ParticleEmitterShapeStyle.Volume -- drops start anywhere inside the box
emitter.EmissionDirection = Enum.NormalId.Bottom
emitter.Speed = NumberRange.new(70, 85)
emitter.Lifetime = NumberRange.new(0.8, 1)
emitter.Orientation = Enum.ParticleOrientation.VelocityParallel -- stretch along the fall
emitter.Squash = NumberSequence.new(2) -- above 0: thinner and taller, a streak
emitter.Size = NumberSequence.new(0.15)
emitter.Transparency = NumberSequence.new(0.4)
emitter.Color = ColorSequence.new(Color3.fromRGB(200, 210, 225))
emitter.LightInfluence = 1
emitter.Rate = 0
if RAIN_TEXTURE ~= "" then
emitter.Texture = RAIN_TEXTURE
end
emitter.Parent = rainBox
local rainSound = Instance.new("Sound")
rainSound.Name = "RainLoop"
rainSound.Looped = true
rainSound.Volume = 0
rainSound.SoundId = RAIN_SOUND_ID
rainSound.Parent = SoundService
local currentRate = 0 -- the rate for this weather, before the roof check
local indoors = false
local fadeInfo = TweenInfo.new(FADE_SECONDS, Enum.EasingStyle.Sine)
local function applyWeather()
local name = workspace:GetAttribute("Weather")
local look = if type(name) == "string" and LOOKS[name] then LOOKS[name] else clear
TweenService:Create(fog, fadeInfo, { Density = look.density, Haze = look.haze, Color = look.color }):Play()
TweenService:Create(Lighting, fadeInfo, { Brightness = look.brightness }):Play()
currentRate = if name == "Storm" then RAIN_RATE * 2 elseif name == "Rain" then RAIN_RATE else 0
local volume = if name == "Storm" then 0.8 elseif name == "Rain" then 0.5 else 0
if volume > 0 and RAIN_SOUND_ID ~= "" and not rainSound.IsPlaying then
rainSound:Play()
end
TweenService:Create(rainSound, fadeInfo, { Volume = volume }):Play()
end
-- Thunder: a quick flash, then the rumble a moment later (sound travels slower than light)
local function onThunder()
if workspace:GetAttribute("Weather") ~= "Storm" then
return
end
local flashUp = TweenService:Create(Lighting, TweenInfo.new(0.08), { ExposureCompensation = 1.5 })
local flashDown = TweenService:Create(Lighting, TweenInfo.new(0.5), { ExposureCompensation = 0 })
flashUp:Play()
flashUp.Completed:Once(function()
flashDown:Play()
end)
if THUNDER_SOUND_ID ~= "" then
task.delay(0.4 + math.random() * 1.2, function()
local thunder = Instance.new("Sound")
thunder.SoundId = THUNDER_SOUND_ID
thunder.Volume = 0.8
thunder.Parent = SoundService
thunder:Play()
thunder.Ended:Once(function()
thunder:Destroy()
end)
end)
end
end
workspace:GetAttributeChangedSignal("Weather"):Connect(applyWeather)
workspace:GetAttributeChangedSignal("ThunderAt"):Connect(onThunder)
applyWeather()
-- Every frame: keep the rain box above the camera. A few times a second: check for a roof.
local roofParams = RaycastParams.new()
local sinceRoofCheck = 0
RunService.RenderStepped:Connect(function(deltaTime: number)
local camera = workspace.CurrentCamera
local position = camera.CFrame.Position
rainBox.CFrame = CFrame.new(position + Vector3.new(0, RAIN_HEIGHT, 0))
sinceRoofCheck += deltaTime
if sinceRoofCheck >= 0.2 then
sinceRoofCheck = 0
local character = player.Character
roofParams.ExcludeInstances = if character then { character } else {}
-- Anything solid above the camera counts as a roof
indoors = workspace:Raycast(position, Vector3.new(0, RAIN_HEIGHT + 60, 0), roofParams) ~= nil
end
emitter.Rate = if indoors then 0 else currentRate
-- Rain sounds muffled indoors instead of stopping
rainSound.PlaybackSpeed = if indoors then 0.85 else 1
end)
The rain box is 90 by 90 studs and sits 40 studs above the camera. Drops start anywhere inside it and fall at 70 to 85 studs a second for about a second, which carries them past the camera and down to the ground around you. Wherever you walk, the box comes with you, so the rain seems to cover the whole map.
Orientation = VelocityParallel lines each particle up with the way it is moving, and a Squash above 0 makes it thinner and taller. Together they turn round dots into falling streaks, even with the default particle image. A proper raindrop texture from the Toolbox looks better still: paste its ID into RAIN_TEXTURE.
Why the rain stops under roofs
Particles fall through everything: they never hit parts. Without a check, it rains inside every house. Five times a second, the script casts a ray straight up from the camera. If it hits anything within 100 studs, there is something over your head, and the emitter's rate is set to 0 until you step back outside. Drops already falling finish their fall, which looks like the last rain dripping off the edge of the roof.
- Invisible parts above your map (for example a big invisible ceiling) also count as a roof. Untick CanQuery on them so rays ignore them.
- Trees count too, so the rain thins under a big tree. Most players like that. To ignore trees, put them in a folder and add it to
roofParams.ExcludeInstances. - The ray starts at the camera, not the character, because that is where the rain is drawn. In first person the two are the same place.
Step 3: Add your own weather
A new weather is one row on the server and one look on the client. For fog without rain, add this row to WEATHERS in WeatherService: { name = "Fog", weight = 2, minSeconds = 90, maxSeconds = 150 }.
Then, in WeatherClient, add a matching entry to LOOKS: Fog = { density = 0.7, haze = 4, color = Color3.fromRGB(190, 195, 200), brightness = clear.brightness * 0.8 }. The rain rate stays 0 for any weather that is not Rain or Storm, so fog only changes the air. For snow, use the same rain box with a slower Speed (about 8 to 12), a longer Lifetime (about 6) and Orientation left at its default, so flakes drift instead of streaking.
If your game also has a day and night cycle, the day and night guide changes ClockTime on the server. That works alongside this system. If your cycle changes Lighting.Brightness too, take Brightness out of LOOKS so the two do not fight.
Step 4: Test it
- Press Play. The first weather is picked straight away, so you may already see rain.
- In the Command Bar, run
workspace:SetAttribute("Weather", "Rain"). Over 6 seconds the sky greys, fog thickens and rain starts. - Walk under a roof or into a building: the rain stops above you and the sound drops in pitch. Walk out: it starts again.
- Run
workspace:SetAttribute("Weather", "Storm"), thenworkspace:SetAttribute("ThunderAt", 1)to force a lightning flash. - Try a phone in the device emulator (Test tab, Device). If it slows down, lower
RAIN_RATE. - Start a 2-player local server from the Test tab: both windows show the same weather at the same time.
Common errors and fixes
If the rain does not show, check the Output window for errors first.
No rain appears
Check the Weather attribute on the Workspace while playing (select Workspace, look at Attributes in the Properties window). If it says Rain and there is still nothing, you are probably under something: look for an invisible part above the spawn and untick its CanQuery.
Rain falls inside buildings
The roof check uses rays, and some roofs are made of parts with CanQuery off, or are MeshParts with no collision geometry. Tick CanQuery on the roof parts.
The fog never goes back to normal
Another script changes the Atmosphere or Lighting after this one starts, so "clear" was saved with the wrong values. Let WeatherClient be the only script that changes Density, Haze, Color and Brightness.
Failed to load sound
The rain or thunder audio ID is wrong or not allowed in your game. Pick another sound from the Toolbox. See Failed to load sound.
Unable to assign property Texture
The texture must be a full asset string such as "rbxassetid://123456", not just the number. See Unable to assign property.
Build it with RoCode
If you would rather not set this up by hand, RoCode can build it in the place you have open. RoCode is an independent AI agent for Roblox Studio, not made by Roblox: you describe the change in a web chat, and its Studio plugin creates the parts and scripts in your Explorer, so there is no code to paste.
Add weather to my map: clear, rain and thunderstorms that change every few minutes and are the same for everyone, rain that stops under roofs, grey fog in storms and a rain sound.
- Can read your place first to see your current Lighting and Atmosphere, so clear weather keeps your look
- Writes the scripts with Create Script and is told to compile-check each one with Check Script
- Sets an undo point before and after each batch of changes, so Ctrl+Z steps back one batch at a time
Questions
How do I make rain in Roblox Studio?
Put a ParticleEmitter pointing down in an invisible part, move that part above the camera every frame from a LocalScript, and set the emitter's Rate when it should rain. Step 2 has the full script with fog and sound.
How do I make a weather system in Roblox?
Let a server Script pick the weather and store it in an attribute on the Workspace, and let each client draw it when the attribute changes. That keeps every player in the same weather with almost no network traffic.
How do I stop rain going through roofs?
Cast a ray up from the camera a few times a second. If it hits something, set the emitter's Rate to 0 until it does not.
Should rain be made on the server or the client?
The client draws it; the server only decides the weather. Rain made on the server would send thousands of particles to every player for nothing.
How do I make fog in Roblox?
Add an Atmosphere to Lighting and raise its Density and Haze. Tween them for a smooth change, as the weather script does.
How do I make lightning?
Tween Lighting.ExposureCompensation up for a split second and back down, then play a thunder sound a moment later. The server sets a ThunderAt attribute so every player sees the flash at the same time.
Sources and further reading
- Roblox Creator Docs: ParticleEmitter. Rate, Shape, Orientation and Squash
- Roblox Creator Docs: Atmosphere. Density, Haze and Color
- Roblox Creator Docs: Lighting. Brightness and ExposureCompensation
- Roblox Creator Docs: Attributes. SetAttribute and GetAttributeChangedSignal
- Roblox Creator Docs: Sound. Looped and Volume
How the code was checked: every script on this page passes Luau's strict type checker against Roblox's API definitions (luau-lsp, 14 November 2026). A type check catches misspelt APIs and wrong types, not game logic, so playtest in Studio before you publish.