o1-preview-2024-09-12· OpenAI
WildChat-4.8M (AI2)
write a roblox script where it's a day and night cycle. loop.
- User
write a roblox script where it's a day and night cycle. loop.
- Assistant
write a roblox script where it's a day and night cycle. loop.
Sure! Below is a Roblox Lua script that creates a continuous day and night cycle by adjusting the game's lighting over time. This script increments the ClockTime property of the Lighting service to simulate the passage of time from day to night and back.
-- Place this script in ServerScriptService or Workspace
local Lighting = game:GetService("Lighting")
-- Variables to control the speed of the cycle
local timeIncrement = 0.05 -- How much the time advances each step (smaller values = smoother transition)
local waitTime = 0.1 -- How long to wait between each step (in seconds)
while true do
-- From morning (6 AM) to night (24 or 0 AM)
for time = 6, 24, timeIncrement do
Lighting.ClockTime = time
wait(waitTime)
end
-- From midnight (0 AM) back to morning (6 AM)
for time = 0, 6, timeIncrement do
Lighting.ClockTime = time
wait(waitTime)
end
end
ClockTime property of the Lighting service controls the current time of day in the game, ranging from 0 to 24, where 0 is midnight.ClockTime advances with each loop iteration. Smaller values result in smoother transitions between times.Insert the Script:
Adjust Settings (Optional):
timeIncrement and waitTime variables at the top of the script.timeIncrement and decrease the waitTime.ClockTime = 6) to midnight (ClockTime = 24 or 0), then back to 6 AM. This simulates a full day.while true loop ensures that the cycle repeats indefinitely.waitTime values, as it could impact game performance.You can further customize the day-night cycle by adjusting other properties of the Lighting service, such as:
For example, to adjust the brightness based on the time of day, you could modify the script like this:
-- Inside the loops, after setting ClockTime
-- Example: Simulate dimmer lighting during the night
if time >= 18 or time <= 6 then
Lighting.Brightness = 1 -- Dimmer at night
else
Lighting.Brightness = 2 -- Brighter during the day
end
Lighting settings, as this could interfere with the day-night cycle.Feel free to ask if you need further assistance or additional features added to the script!
Not yet included in a published release.