§ How to · with Forge AI
How to make a Roblox day night cycle (with AI)
By Sametcan Tasgiran, Founder & Developer·Published ·Updated
A Roblox day night cycle needs four pieces: time of day progression, sun and moon transition, atmospheric color shifts, and event triggers (e.g., night spawn). Forge AI generates all four in 28 seconds.
3 files · 90 lines · 28 seconds · 1 credit. 24-minute realtime full cycle, configurable.
Configurable cycle length
Default 24 minutes per full day. Configurable to any duration (faster for action games, slower for relaxed games).
Sun and moon
Lighting.ClockTime drives sun position. Moon rises after sunset, sets before sunrise. Continuous sky transition with no jarring cuts.
Atmospheric color shifts
Dawn (warm orange), Day (clear), Dusk (purple-pink), Night (deep blue) — all interpolated continuously via Atmosphere properties.
Night event triggers
Configurable callbacks fire at sunset, sunrise, midnight. Use for spawning enemies, lighting torches, opening shops.
Per-player time skip
Sleep mechanic — interact with a bed to skip forward 6 hours. Server validates only one sleeper at a time (configurable to require party consensus).
Weather integration
Time of day affects weather chance — rain more likely at dusk, fog more common at night. Configurable in WeatherConfig.
Files Forge AI ships for this prompt
3 files · 90 lines · 28 seconds · 1 credit
ServerScriptService/DayNightCycle.lua
Time progression, sky transition, callback dispatch
48 lines
ReplicatedStorage/Modules/CycleConfig.lua
Cycle length, callback registrations, color palettes
24 lines
ServerScriptService/SleepHandler.lua
Bed interaction → time skip
18 lines
Sample output: ServerScriptService/DayNightCycle.lua
--!strict
-- ServerScriptService/DayNightCycle.lua (Forge AI · excerpt)
local Lighting = game:GetService("Lighting")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Config = require(ReplicatedStorage.Modules.CycleConfig)
local CYCLE_SECONDS = Config.cycleMinutes * 60
local HOURS_PER_SECOND = 24 / CYCLE_SECONDS
local atmosphere = Lighting:FindFirstChildOfClass("Atmosphere") or Instance.new("Atmosphere", Lighting)
local function lerpColor(a: Color3, b: Color3, t: number): Color3
return Color3.new(a.R + (b.R - a.R) * t, a.G + (b.G - a.G) * t, a.B + (b.B - a.B) * t)
end
local lastHour = -1
task.spawn(function()
while true do
local newTime = (Lighting.ClockTime + HOURS_PER_SECOND * 1) % 24
Lighting.ClockTime = newTime
-- Interpolate atmosphere color based on time
if newTime >= 5 and newTime < 7 then -- dawn
local t = (newTime - 5) / 2
atmosphere.Color = lerpColor(Config.colors.night, Config.colors.dawn, t)
elseif newTime >= 7 and newTime < 17 then -- day
atmosphere.Color = Config.colors.day
elseif newTime >= 17 and newTime < 19 then -- dusk
local t = (newTime - 17) / 2
atmosphere.Color = lerpColor(Config.colors.day, Config.colors.dusk, t)
else -- night
atmosphere.Color = Config.colors.night
end
-- Fire callbacks on hour change
local currentHour = math.floor(newTime)
if currentHour ~= lastHour then
local callback = Config.hourCallbacks[currentHour]
if callback then callback() end
lastHour = currentHour
end
task.wait(1)
end
end)Building a Roblox day night cycle
Day-night cycles are atmosphere multipliers. A static-time Roblox game feels frozen; a game that visually progresses through morning, day, dusk, and night feels alive. The technical work is modest — Lighting.ClockTime and Atmosphere properties drive most of it — but the gameplay impact is large. Forge AI ships the full cycle in 28 seconds.
The Forge AI day-night prompt produces a 3-file system. CycleConfig.lua holds the cycle length, color palette, and hour-based callback table. DayNightCycle.lua runs a loop that advances ClockTime and interpolates Atmosphere.Color through the four canonical phases (dawn, day, dusk, night). SleepHandler.lua handles bed interaction for time-skip.
Cycle length is the design lever. Default 24 minutes feels balanced for most games — short enough that night happens during a single play session, long enough that day phases feel meaningful. Action games can drop to 8 minutes for faster turnover. Relaxed builder games can stretch to 60+ minutes.
The sun-and-moon transition is automatic. Lighting.ClockTime drives Roblox's native skybox sun position. At 18:00 the sun dips below the horizon; the moon rises automatically. No manual sky management needed. The atmosphere color interpolation runs in parallel — warm dawn tones, clear day, purple dusk, deep blue night.
Hour callbacks are the gameplay integration layer. Register a function for each hour in CycleConfig. At 18:00, spawn nocturnal enemies. At 22:00, close shops. At 06:00, reset daily quests. This pattern hooks the entire game economy into the time cycle without scattering time checks everywhere — one config, many behaviors.
The sleep mechanic is the player agency layer. Click a bed to skip 6 hours forward. Useful for players who want to play in their preferred lighting (night for moody horror games, day for builder games). Server-validated to prevent griefing — only one player needs to sleep, but the time skip affects all players equally, which is a standard Minecraft-style convention.
See more on the Luau generator, the game builder, or browse the full blog.
Frequently asked
How do I trigger something at sunset?+
Register a callback in CycleConfig.lua: hourCallbacks[18] = function() ... end. Fires once when the clock hits 18:00 (6 PM). Common uses: spawn nocturnal enemies, light street lamps, close shops.
Can players sleep through the night?+
Yes. SleepHandler.lua handles bed interactions. Click a bed → server advances time by 6 hours. Configurable to require multiple players to sleep (party consensus) for multiplayer games.
How does time sync across players?+
Lighting.ClockTime is server-replicated. All clients see the same time automatically. No custom sync needed.
What about real-world time integration?+
CycleConfig has a 'realtime = true' flag. When enabled, time in-game tracks UTC (12 noon UTC = 12 noon in-game). Useful for community events ('this event only happens at midnight UTC').
Can I have different cycles per region?+
Yes. Multiple instances of DayNightCycle.lua can run with different ClockTime targets in different Workspace regions. This requires custom region detection but Forge can extend in a follow-up.
Related Forge AI prompts
Roblox tycoon
9 files · 260 lines · 1m 04s · 1 credit. Per-player tycoon plots cloned from ReplicatedStorage.
Roblox pet system
11 files · 340 lines · 1m 28s · 1 credit. Pets persist across server restarts, trade-safe by default.
Roblox shop system
5 files · 180 lines · 47 seconds · 1 credit. Robux + in-game currency, both server-validated.