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.

  1. Insert a Script into ServerScriptService and paste the code. Change DAY_LENGTH_MINUTES to taste.

The script

ServerScriptService > DayNight (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

  • ClockTime is the in-game hour from 0 to 24; Roblox moves the sun, moon and sky to match.
  • Heartbeat runs 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 TimeOfDay as a string every frame — ClockTime is 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.Ambient or OutdoorAmbient a 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.

Keep reading