RB-004
Roblox day and night cycle script
Moves the sun and moon so the game goes through a full day over a set time.
- Script type
- Script
- Where it goes
- ServerScriptService
- Category
- World and effects
For your own game in Roblox Studio. Not for use in other people's games.
The code
-- Day and night cycle: changes Lighting.ClockTime from 0 to 24 over and over.
local DAY_LENGTH_SECONDS = 600 -- real seconds for one full 24 hour game day
local START_HOUR = 8 -- the hour the game starts at (0 to 24)
local STEP_SECONDS = 0.25 -- how often the clock updates
local Lighting = game:GetService("Lighting")
Lighting.ClockTime = START_HOUR
local hoursPerStep = 24 / DAY_LENGTH_SECONDS * STEP_SECONDS
while true do
Lighting.ClockTime = (Lighting.ClockTime + hoursPerStep) % 24
task.wait(STEP_SECONDS)
endHow to set it up
- In the Explorer, find ServerScriptService.
- Click the plus button next to it and add a Script.
- Paste the code.
- Play. Watch the sky change. Try DAY_LENGTH_SECONDS = 60 to see it fast.
Change it
- ClockTime 12 is noon and 0 is midnight.
- Lighting.Brightness and Ambient do not change by themselves. Set them to values that look fine at night too.
- Make the night shorter by skipping hours when ClockTime is between 20 and 6.
More in World and effects
More Roblox tools
- Shirt and pants templatesFree Roblox clothing templates to download: hoodies, jerseys, jeans, joggers and more.
- Robux tax calculatorWork out what you receive after the marketplace fee, or what to charge.
- Robux to USD calculatorConvert earned Robux to dollars at a DevEx rate you can edit.
- Shirt and pants template makerColour each panel of the 585×559 clothing template and download it.
- Username generatorGenerate usernames that fit the 3–20 character rule.