Tutorial · Gameplay

How to make a day and night cycle in Roblox Studio

Roblox's sky, sun and shadows all follow one number: Lighting.ClockTime, the time of day in hours. It never moves on its own, so a day and night cycle is a short server script that adds a little to it every frame. This guide builds that, then makes street lights turn on at dusk and off at dawn.

Updated 23 October 20265 min readBeginnerLuau

In short

Put a Script in ServerScriptService that connects to RunService.Heartbeat and adds deltaTime * 24 / (DAY_MINUTES * 60) to Lighting.ClockTime, wrapping at 24. The server owns Lighting, so every player sees the same time.

  • Use deltaTime, not a fixed step in a wait() loop, so the day length stays right when the server is busy.
  • ClockTime is in hours from 0 to 24: 6 is sunrise, 12 is noon, 18 is sunset.
  • Lights follow the clock with GetPropertyChangedSignal("ClockTime"), switching only when day turns to night.

Get the script

Day and night cycle script

One Script in ServerScriptService turns Lighting.ClockTime so a full day and night takes 10 real minutes, the same for every player.

Script in ServerScriptService named DayNightCycle
-- Script in ServerScriptService named DayNightCycle.
-- Runs a full day in DAY_MINUTES real minutes. Lighting changes reach every player.
local Lighting = game:GetService("Lighting")
local RunService = game:GetService("RunService")

local DAY_MINUTES = 10 -- real minutes for one whole day and night
local START_HOUR = 8 -- the time of day when the server starts (0 to 24)

local hoursPerSecond = 24 / (DAY_MINUTES * 60)
Lighting.ClockTime = START_HOUR

RunService.Heartbeat:Connect(function(deltaTime: number)
	Lighting.ClockTime = (Lighting.ClockTime + deltaTime * hoursPerSecond) % 24
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

Explorer: one Script
ServerScriptService
  DayNightCycle Script new

Settings you can change

DAY_MINUTESIn the script
Real minutes for one whole day and night. Default: 10.
START_HOURIn the script
The time of day when a server starts, from 0 to 24. Default: 8.

Type-checked with luau-lsp strict against Roblox's API definitions on 23 October 2026. Not playtested in Studio yet: press Play and watch the Output window before you publish.

Prompt for RoCode

Add a day and night cycle: a Script in ServerScriptService that advances Lighting.ClockTime every Heartbeat using deltaTime so a full day takes 10 minutes, starting at 8 in the morning, and makes every part tagged StreetLight turn its lights on from 6 pm to 6:30 am.

On this page
  1. Get the script
  2. How it works
  3. 1. The cycle
  4. 2. Street lights
  5. Going further
  6. Common errors
  7. With RoCode
  8. Questions
  9. Sources

How time of day works in Roblox

The Lighting service holds the time of day in two linked properties: ClockTime, a number of hours, and TimeOfDay, the same time as text like "14:30:00". Change one and the other follows, and the sun, moon, sky colour and shadows move to match. Roblox's Lighting reference notes that it does not track real time and only changes when a script changes it.

Useful ClockTime values
ClockTimeWhat you see
0Midnight
6Sunrise
12Noon, the sun overhead
18Sunset

Step 1: Turn the clock

Insert a Script in ServerScriptService named DayNightCycle:

Script in ServerScriptService named DayNightCycle
-- Script in ServerScriptService named DayNightCycle.
-- Runs a full day in DAY_MINUTES real minutes. Lighting changes reach every player.
local Lighting = game:GetService("Lighting")
local RunService = game:GetService("RunService")

local DAY_MINUTES = 10 -- real minutes for one whole day and night
local START_HOUR = 8 -- the time of day when the server starts (0 to 24)

local hoursPerSecond = 24 / (DAY_MINUTES * 60)
Lighting.ClockTime = START_HOUR

RunService.Heartbeat:Connect(function(deltaTime: number)
	Lighting.ClockTime = (Lighting.ClockTime + deltaTime * hoursPerSecond) % 24
end)

A day is 24 hours of game time in DAY_MINUTES * 60 real seconds, so each real second adds 24 / (DAY_MINUTES * 60) hours: 0.04 with the default 10 minutes. Heartbeat passes the seconds since the last frame, so the sum stays right however fast the server runs. The % 24 wraps midnight back to 0.

Step 2: Street lights that turn on at night

  1. Make a lamp: a part for the bulb with a PointLight or SpotLight inside it.
  2. Tag the bulb part StreetLight in the Properties window, under Tags. A tagged Model works too: every light inside it switches.
  3. Insert a second Script in ServerScriptService named StreetLights:
Script in ServerScriptService named StreetLights
-- Script in ServerScriptService named StreetLights.
-- Turns on every light inside parts tagged "StreetLight" at night, and off by day.
local CollectionService = game:GetService("CollectionService")
local Lighting = game:GetService("Lighting")

local LIGHTS_ON_HOUR = 18 -- 6 pm
local LIGHTS_OFF_HOUR = 6.5 -- 6:30 am

local function isNight(): boolean
	local hour = Lighting.ClockTime
	return hour >= LIGHTS_ON_HOUR or hour < LIGHTS_OFF_HOUR
end

local function setLamp(lamp: Instance, on: boolean)
	for _, child in lamp:GetDescendants() do
		if child:IsA("Light") then
			child.Enabled = on
		end
	end
	if lamp:IsA("BasePart") then
		lamp.Material = if on then Enum.Material.Neon else Enum.Material.SmoothPlastic
	end
end

local lightsOn: boolean? = nil
local function update()
	local night = isNight()
	if night == lightsOn then
		return -- nothing changed since the last check
	end
	lightsOn = night
	for _, lamp in CollectionService:GetTagged("StreetLight") do
		setLamp(lamp, night)
	end
end

Lighting:GetPropertyChangedSignal("ClockTime"):Connect(update)
CollectionService:GetInstanceAddedSignal("StreetLight"):Connect(function(lamp: Instance)
	setLamp(lamp, isNight())
end)
update()

GetPropertyChangedSignal("ClockTime") fires every time the cycle moves the clock, which is every frame. The script only works out whether it is night and returns straight away unless that answer changed, so the lamps are touched twice a day, not 60 times a second. A bulb part also switches to Neon, so it glows.

Going further: night mood and a clock on screen

  • Darker nights: in the same Heartbeat, lower Lighting.Brightness or change Lighting.OutdoorAmbient when ClockTime is after 18 or before 6.
  • A clock in the corner: a LocalScript can show Lighting.TimeOfDay, which is already formatted as text, in a TextLabel and update it on GetPropertyChangedSignal("TimeOfDay").
  • Night events: the same day or night check can start a round or spawn night-only NPCs.

Test it

  1. Set DAY_MINUTES to 1 so you can watch a whole day.
  2. Press Play. The sun crosses the sky, the sky darkens and the street lights switch on at 6 pm.
  3. Select Lighting in the Explorer during the test (on the Server view) and watch ClockTime count up.
  4. Set DAY_MINUTES back before you publish.

Common errors and fixes

If the sun does not move, check the Output window for a red line first.

The time does not change

The script must be a Script in ServerScriptService. Also check nothing else sets ClockTime or TimeOfDay every frame, such as a free model with its own clock.

The day is far too fast or slow

Change DAY_MINUTES. 10 means 10 real minutes per full day and night.

Street lights never turn on

Check the tag is exactly StreetLight and that the light objects (PointLight, SpotLight or SurfaceLight) are inside the tagged part or model.

Each player sees a different time

The clock is being changed by a LocalScript. Run the cycle on the server only.

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 scripts and objects in your Explorer.

You type

Add a 12 minute day and night cycle with darker nights, and street lamps along my road that turn on at sunset and off at sunrise.

RoCode does
  • Writes the cycle and lamp scripts, and can build the lamp models along a path you describe
  • Is told to compile-check each script with Check Script before it finishes
  • Sets undo points around each batch of changes

RoCode can also build themed world islands (volcano, canyon, jungle and snow) in one call, which pair well with a day and night cycle. You still watch a full day in a playtest to judge the mood. How RoCode connects to Studio.

Questions

How do I make a day and night cycle in Roblox?

Add a little to Lighting.ClockTime every Heartbeat on the server, scaled by deltaTime, and wrap it at 24. Step 1 has the script.

How do I make it always night in Roblox Studio?

Without a cycle script, set Lighting's ClockTime to 0 (or TimeOfDay to 00:00:00) in the Properties window.

What is the difference between ClockTime and TimeOfDay?

They hold the same time: ClockTime as a number of hours, TimeOfDay as text such as "14:30:00". Changing one changes the other.

How long should a Roblox day be?

It is a design choice. Short days (a few minutes) make the change visible in one session; long days suit calm games. This script takes any length.

Sources and further reading

How the code was checked: every script on this page passes Luau's strict type checker against Roblox's API definitions (luau-lsp, 23 October 2026). A type check catches misspelt APIs and wrong types, not game logic, so playtest in Studio before you publish.

Try RoCode on your own place.

Free every day, no card required. Install the plugin, describe the feature, and review what lands in Studio.