§ How to · with Picoo
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). Describe the cycle you want and Picoo writes the scripts for it. The build below is one example of that output.
Example build: 3 files · 90 lines. Picoo writes this code for each prompt, so file names and line counts vary from run to run. A full day takes 24 real minutes in this example.
Configurable cycle length
A full day takes 24 real minutes in this example. cycleMinutes in CycleConfig sets any length: shorter for action games, longer for relaxed ones.
Sun and moon
Lighting.ClockTime drives the sun and moon, so advancing it once a second moves both across the sky with no extra sky code.
Atmospheric color shifts
Atmosphere.Color blends from the night color to the dawn color between 05:00 and 07:00, and from the day color to the dusk color between 17:00 and 19:00, using the palette in CycleConfig.
Night event triggers
hourCallbacks in CycleConfig maps an hour to a function that runs once when the clock reaches it. Use it to spawn enemies at 18:00, light torches or open shops.
Sleep time-skip
Interacting with a bed skips the clock forward 6 hours. Lighting is shared, so the skip applies to everyone in the server.
Same time for every player
The cycle runs in a server Script, and Lighting.ClockTime replicates to every client, so all players see the same time without extra sync code.
Example output from a build like this
3 files in this example. Picoo writes this code for your prompt, so file names and sizes vary.
ServerScriptService/DayNightCycle.lua
Time progression, sky transition, callback dispatch
ReplicatedStorage/Modules/CycleConfig.lua
Cycle length, callback registrations, color palettes
ServerScriptService/SleepHandler.lua
Bed interaction → time skip
Sample output: ServerScriptService/DayNightCycle.lua
--!strict
-- ServerScriptService/DayNightCycle.lua (Picoo · 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. Here is one example of what Picoo writes for it.
In this example Picoo wrote three files. CycleConfig.lua holds the cycle length, color palette, and hour-based callback table. DayNightCycle.lua runs a server loop that advances ClockTime once a second and blends Atmosphere.Color at dawn and dusk. SleepHandler.lua handles bed interaction for the time-skip.
Cycle length is the design lever. This example uses 24 minutes per day, one in-game hour per real minute: short enough that night happens during a single play session, long enough that each phase lasts. Action games can drop to 8 minutes for faster turnover; relaxed builder games can stretch to 60 or more.
The sun and moon need no code of their own. Lighting.ClockTime drives Roblox's sky, so as the clock passes 18:00 the sun goes down and the moon comes up. The Atmosphere color changes alongside it, blending from night to dawn between 05:00 and 07:00 and from day to dusk between 17:00 and 19:00.
Hour callbacks are the gameplay integration layer. Register a function for an hour in CycleConfig: at 18:00, spawn nocturnal enemies; at 22:00, close shops; at 06:00, reset daily quests. The loop runs each callback once when the clock reaches its hour, so the game hooks into the time of day from one config table instead of time checks scattered everywhere.
The sleep mechanic gives players some control. Clicking a bed skips 6 hours forward, which suits players who want their preferred lighting: night for moody horror games, day for builder games. Lighting is shared, so in this example one player sleeping moves the clock for everyone. For a vote or a minimum number of sleepers, ask in a follow-up prompt.
See more on the Luau generator, the AI Luau script writer, the 3D model generator and the game builder, read how Picoo compares with ChatGPT, or browse the full blog.
Frequently asked
How do I trigger something at sunset?+
Register a callback in CycleConfig.lua: hourCallbacks[18] = function() ... end. It fires once when the clock reaches 18:00 (6 PM). Common uses: spawn nocturnal enemies, light street lamps, close shops.
Can players sleep through the night?+
In this example, yes: SleepHandler.lua listens for bed interactions and moves the clock forward 6 hours for the whole server. To require several players to sleep first, ask for a sleeper count or a vote in a follow-up prompt.
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?+
Ask for it in the prompt. A UTC-driven clock sets ClockTime from os.time() instead of adding to it, so 12:00 UTC is noon in-game on every server. It suits community events that happen at a fixed hour.
Can I have different cycles per region?+
Lighting is global, so a server Script sets one time for the whole place. For different times in different areas, the clock has to move to the client: a LocalScript sets Lighting.ClockTime for each player based on the area they are in. Ask for that in a follow-up prompt.
Does Picoo have a built-in day-night option?+
Its cinematic_atmosphere lighting recipe has one. With day_night_cycle turned on, the lighting setup script advances Lighting.ClockTime once a second, so a full day takes 180 seconds; cycle_duration_seconds changes that. It moves the clock only. Color blending, hour callbacks and sleep are extra code like the example on this page.
Related Picoo prompts
Roblox tycoon
19 files · 5,513 lines, 2,268 of them the vendored ProfileStore module · one recipe call. Plot1 is built in Edit mode; plots 2-6 are copies of it made when the server starts.
Roblox pet system
6 files · 1,165 lines · one recipe call. Eggs, rarity, trading and an inventory UI are follow-up prompts that call PetServer.grant and the EquipPet remote.
Roblox shop system
8 files · 1,259 lines, 852 of them the shared PicooFeedback module · one recipe call. Three starter items by default; name your own items and prices in the prompt.