Forja

Roblox day and night cycle script

The sun moves on its own, so a full day passes in a few real minutes.

Where it goes

  1. 1In the Explorer, hover over ServerScriptService, press + and choose Script.
  2. 2Delete what's in it and paste this in.
  3. 3Press Play and watch the sun move.
DayNightCycle · a Script in ServerScriptService
-- From forja.us/tools/roblox-scripts/day-night-cycle-- A full day takes DAY_MINUTES real minutes.local Lighting = game:GetService("Lighting")local DAY_MINUTES = 10local STEP_SECONDS = 0.5local hoursPerStep = STEP_SECONDS * 24 / (DAY_MINUTES * 60)while true do	Lighting.ClockTime = (Lighting.ClockTime + hoursPerStep) % 24	task.wait(STEP_SECONDS)end

How it works

  • ClockTime is the hour of the day from 0 to 24, and the sun follows it.
  • % 24 starts the day over after midnight.
  • It moves twice a second: smooth enough to look right, without sending constant updates to every player.

Make it yours

A longer day
Change DAY_MINUTES.
Longer nights
Use a bigger hoursPerStep by day and a smaller one between hours 18 and 6, with an if on Lighting.ClockTime.
Want something more? The script generator can write it: “A day and night cycle that turns street lights on at night and off in the morning”

Maps to try it on: city and town maps

Start from a finished map, and your scripts have a game to run in.

More free Roblox scripts