Roblox day and night cycle script
A smooth day and night cycle where you choose how many real minutes a full day lasts — plus how to run events at night.
ScriptUpdated November 2, 2026
Where to put it
Script — ServerScriptService > DayNight (Script). It runs on the server, so players can't change what it does.
- Insert a Script into ServerScriptService and paste the code. Change
DAY_LENGTH_MINUTESto taste.
The script
local Lighting = game:GetService("Lighting")
local RunService = game:GetService("RunService")
local DAY_LENGTH_MINUTES = 12 -- one full 24-hour day
local hoursPerSecond = 24 / (DAY_LENGTH_MINUTES * 60)
RunService.Heartbeat:Connect(function(dt)
Lighting.ClockTime = (Lighting.ClockTime + dt * hoursPerSecond) % 24
end)How it works
ClockTimeis the in-game hour from 0 to 24; Roblox moves the sun, moon and sky to match.Heartbeatruns every frame, so the change is smooth instead of jumping.- Running it on the server keeps every player at the same time of day.
Variations
Do something at night
Turn on street lights or spawn monsters when it gets dark.
local wasNight = false
Lighting:GetPropertyChangedSignal("ClockTime"):Connect(function()
local isNight = Lighting.ClockTime >= 18 or Lighting.ClockTime < 6
if isNight ~= wasNight then
wasNight = isNight
for _, light in workspace.StreetLights:GetDescendants() do
if light:IsA("PointLight") then light.Enabled = isNight end
end
end
end)Common mistakes
- Changing
TimeOfDayas a string every frame —ClockTimeis a number and much simpler. - Running the cycle in a LocalScript: each player sees a different time.
- Nights that are too dark to play: raise
Lighting.AmbientorOutdoorAmbienta little.
FAQ
How do I make the Roblox day cycle faster or slower?
Change DAY_LENGTH_MINUTES. The script converts it into how many in-game hours pass per real second.
How do I start the game at night?
Set Lighting.ClockTime to a value like 21 in Properties; the cycle continues from there.