You can write your topic however you want, but you need to answer these questions:
-
**What do you want to achieve? I want to change my lighting settings, depeding the time of the day. But the script somehow it doesn’t work.
-
**What is the issue? We’ll bascailly. The time is stopped and not moving, the script is basically doing nothing
-
**What solutions have you tried so far? I’ve tried adding the lighting thingy from this page: Lighting | Roblox Creator Documentation, but it just doesn’t work. And also asked chat GPT and doesn’t work also.
local DayNightCycle = {}
local Lighting = game:GetService("Lighting")
local DaySettings = {
Ambient = Color3.fromRGB(0, 0, 0),
Brightness = 2,
ColorShift_Bottom = Color3.fromRGB(1, 0, 0),
ColorShift_Top = Color3.fromRGB(0, 0, 0),
EnvironmentDiffuseScale = 0.5,
EnvironmentSpecularScale = 0,
OutdoorAmbient = Color3.fromRGB(0, 0, 0)
}
local SunsetSettings = {
Ambient = Color3.fromRGB(255, 83, 13),
Brightness = 2,
ColorShift_Bottom = Color3.fromRGB(255, 66, 32),
ColorShift_Top = Color3.fromRGB(255, 103, 68),
EnvironmentDiffuseScale = 0.5,
EnvironmentSpecularScale = 0,
OutdoorAmbient = Color3.fromRGB(63, 32, 33)
}
local NightSettings = {
Ambient = Color3.fromRGB(0, 0, 0),
Brightness = 0.5,
ColorShift_Bottom = Color3.fromRGB(0, 0, 0),
ColorShift_Top = Color3.fromRGB(0, 0, 0),
EnvironmentDiffuseScale = 0.1,
EnvironmentSpecularScale = 0,
OutdoorAmbient = Color3.fromRGB(0, 0, 0)
}
function DayNightCycle.UpdateTimeOfDay(time)
if time >= 6 and time < 18 then
SetLightingSettings(DaySettings)
elseif time >= 18 and time < 20 then
SetLightingSettings(SunsetSettings)
else
SetLightingSettings(NightSettings)
end
end
function SetLightingSettings(settings)
for property, value in pairs(settings) do
Lighting[property] = value
end
end
return DayNightCycle
Server Framework:
local RunService = game:GetService("RunService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local MainGame = ReplicatedStorage:WaitForChild("MainGame")
local Modules = MainGame.Modules
local DayNightCycle = require(Modules.Time)
local function UpdateTime()
local currentTime = os.date("*t").hour
DayNightCycle.UpdateTimeOfDay(currentTime)
end
local updateInterval = 1 -- Time update interval in seconds
local timer = 0
RunService.Heartbeat:Connect(function(deltaTime)
timer = timer + deltaTime
if timer >= updateInterval then
UpdateTime()
timer = 0
end
end)