CUBE BURSTSTUDIOS
day-night-cycle.zip
Details

Day / Night Cycle with Street Lamps

Smooth day/night with separate day and night lengths, softer night lighting and lamps that switch on at dusk.

Category
Code
File
day-night-cycle.zip
Size
1.6 KB
Downloads
0
Added
16 Oct 2026
Licence
Free to use, no credit needed (CC0)

#lighting#day night#time#atmosphere#luau#roblox#script

⚑ Report this

Smooth day/night with separate day and night lengths, softer night lighting and lamps that switch on at dusk.

Smooth day/night with separate day and night lengths, softer night lighting, and lamps that switch on at dusk.

SETUP
1. Put this Script in ServerScriptService. Tweak the settings below.
2. Optional street lamps: give any Light (PointLight/SpotLight/SurfaceLight) or neon Part the tag
"NightLight" (Studio: select it > Properties > Tags). They turn on at night and off in the day.

The main script is shown below with a Copy button, or grab the download with every file and a README.

DayNightCycle.server.lua
--[[
	Day / Night Cycle  ·  by Cube Burst Studios  ·  CC0
	Smooth day/night with separate day and night lengths, softer night lighting, and lamps that switch on at dusk.

	SETUP
	1. Put this Script in ServerScriptService. Tweak the settings below.
	2. Optional street lamps: give any Light (PointLight/SpotLight/SurfaceLight) or neon Part the tag
	   "NightLight" (Studio: select it > Properties > Tags). They turn on at night and off in the day.
]]

local Lighting = game:GetService("Lighting")
local TweenService = game:GetService("TweenService")
local CollectionService = game:GetService("CollectionService")

local DAY_MINUTES = 8 -- real minutes from 6:00 to 18:00
local NIGHT_MINUTES = 4 -- real minutes from 18:00 to 6:00
local START_HOUR = 9

local DAY_LOOK = { Ambient = Color3.fromRGB(140, 140, 150), OutdoorAmbient = Color3.fromRGB(150, 150, 160), Brightness = 2.5 }
local NIGHT_LOOK = { Ambient = Color3.fromRGB(40, 45, 80), OutdoorAmbient = Color3.fromRGB(55, 60, 100), Brightness = 0.6 }

local function isNight(hour)
	return hour < 6 or hour >= 18
end

local function setLamps(on)
	for _, thing in ipairs(CollectionService:GetTagged("NightLight")) do
		if thing:IsA("Light") then
			thing.Enabled = on
		elseif thing:IsA("BasePart") then
			thing.Material = on and Enum.Material.Neon or Enum.Material.SmoothPlastic
		end
	end
end

local function changeLook(night)
	TweenService:Create(Lighting, TweenInfo.new(6, Enum.EasingStyle.Sine), night and NIGHT_LOOK or DAY_LOOK):Play()
	setLamps(night)
end

Lighting.ClockTime = START_HOUR
local night = isNight(START_HOUR)
changeLook(night)
-- lamps added later (e.g. a map loading in) should match the current time
CollectionService:GetInstanceAddedSignal("NightLight"):Connect(function()
	setLamps(night)
end)

local last = os.clock()
while true do
	task.wait(0.1)
	local now = os.clock()
	local dt = now - last
	last = now
	local hour = Lighting.ClockTime
	-- 12 in-game hours take DAY_MINUTES (day) or NIGHT_MINUTES (night) real minutes
	local hoursPerSecond = 12 / ((isNight(hour) and NIGHT_MINUTES or DAY_MINUTES) * 60)
	Lighting.ClockTime = (hour + dt * hoursPerSecond) % 24
	local nowNight = isNight(Lighting.ClockTime)
	if nowNight ~= night then
		night = nowNight
		changeLook(night)
	end
end

MORE
CODE

View all ↗