Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

My Lighting Changer which is based of ClockTime isn't Working, What am I Doing Wrong?

So i've made a script a few hours ago, have tried some fixes but it still doesn't work

The Script:

local RS = game:GetService("ReplicatedStorage")
local DayBox = RS.SkyBoxes:WaitForChild("Sunset Orange")
local NightBox = RS.SkyBoxes:WaitForChild("Dark Skies")
local Lighting = game:WaitForChild("Lighting")
local TOD = Lighting.TimeOfDay
local Ambient = Lighting.Ambient
local OutdoorAmbient = Lighting.OutdoorAmbient
local ColorShiftTop = Lighting.ColorShift_Top
local ColorShiftBottom = Lighting.ColorShift_Bottom
local FogColor = Lighting.FogColor
local FogStart = Lighting.FogStart
local FogEnd = Lighting.FogEnd

if TOD == "5:30:00" then
	Ambient = Color3.fromRGB(0,0,255)
	OutdoorAmbient = Color3.fromRGB(0,0,127)
	ColorShiftTop = Color3.fromRGB(255,242,242)
	ColorShiftBottom = Color3.fromRGB(85,170,255)
	FogColor = Color3.fromRGB(85,170,255)
	FogStart = "100"
	FogEnd = "500"
	--Morning
elseif TOD == "6:00:00" then
	Ambient = Color3.fromRGB(255,255,0)
	OutdoorAmbient = Color3.fromRGB(255,255,0)
	ColorShiftTop = Color3.fromRGB(255,255,0)
	ColorShiftBottom = Color3.fromRGB(255,255,255)
	FogColor = Color3.fromRGB(255,255,255)
	FogStart = "250"
	FogEnd = "100000"
	--Sunset
elseif TOD == "17:30:00" then
	Ambient = Color3.fromRGB(255,170,0)
	OutdoorAmbient = Color3.fromRGB(255,170,0)
	ColorShiftTop = Color3.fromRGB(255,170,0)
	ColorShiftBottom = Color3.fromRGB(255,255,0)
	FogColor = Color3.fromRGB(255,170,0)
	FogStart = "250"
	FogEnd = "100000"
	--Night
elseif TOD == "18:00:00" then
	Lighting:WaitForChild("Sunset Orange"):Destroy()
	local NightTime = NightBox:Clone()
	NightTime.Parent = Lighting
	Ambient = Color3.fromRGB(39,76,143)
	OutdoorAmbient = Color3.fromRGB(85,0,127)
	ColorShiftTop = Color3.fromRGB(0,0,255)
	ColorShiftBottom = Color3.fromRGB(143,235,255)
	FogColor = Color3.fromRGB(85,170,255)
	FogStart = "100"
	FogEnd = "500"
end

1 answer

Your script doesnt work properly because the code is passed only 1 time: when the server boots. Heres a version that works:

local RS = game:GetService("ReplicatedStorage")
local DayBox = RS.SkyBoxes:WaitForChild("Sunset Orange")
local NightBox = RS.SkyBoxes:WaitForChild("Dark Skies")
local Lighting = game:WaitForChild("Lighting")
--local TOD = Lighting.TimeOfDay --value is set only 1 time, therefore its kinda useless.
local Ambient = Lighting.Ambient
local OutdoorAmbient = Lighting.OutdoorAmbient
local ColorShiftTop = Lighting.ColorShift_Top
local ColorShiftBottom = Lighting.ColorShift_Bottom
local FogColor = Lighting.FogColor
local FogStart = Lighting.FogStart
local FogEnd = Lighting.FogEnd

Lighting:GetPropertyChangedSignal("TimeOfDay"):Connect(function() --runs code if it changes
local TOD = Lighting.TimeOfDay
if TOD == "5:30:00" then -- "5:30:00" is a string because it has colons (these things : idk the name of them too :/)
    Ambient = Color3.fromRGB(0,0,255)
    OutdoorAmbient = Color3.fromRGB(0,0,127)
    ColorShiftTop = Color3.fromRGB(255,242,242)
    ColorShiftBottom = Color3.fromRGB(85,170,255)
    FogColor = Color3.fromRGB(85,170,255)
    FogStart = 100--Strings arent numbers, remove the " thingys (i dont know their names :/)
    FogEnd = 500
    --Morning
elseif TOD == "6:00:00" then
    Ambient = Color3.fromRGB(255,255,0)
    OutdoorAmbient = Color3.fromRGB(255,255,0)
    ColorShiftTop = Color3.fromRGB(255,255,0)
    ColorShiftBottom = Color3.fromRGB(255,255,255)
    FogColor = Color3.fromRGB(255,255,255)
    FogStart = 250
    FogEnd = 100000
    --Sunset
elseif TOD == "17:30:00" then
    Ambient = Color3.fromRGB(255,170,0)
    OutdoorAmbient = Color3.fromRGB(255,170,0)
    ColorShiftTop = Color3.fromRGB(255,170,0)
    ColorShiftBottom = Color3.fromRGB(255,255,0)
    FogColor = Color3.fromRGB(255,170,0)
    FogStart = 250
    FogEnd = 100000
    --Night
elseif TOD == "18:00:00" then
    Lighting:WaitForChild("Sunset Orange"):Destroy()
    local NightTime = NightBox:Clone()
    NightTime.Parent = Lighting
    Ambient = Color3.fromRGB(39,76,143)
    OutdoorAmbient = Color3.fromRGB(85,0,127)
    ColorShiftTop = Color3.fromRGB(0,0,255)
    ColorShiftBottom = Color3.fromRGB(143,235,255)
    FogColor = Color3.fromRGB(85,170,255)
    FogStart = 100
    FogEnd = 500
end
end)

clocktime version

local RS = game:GetService("ReplicatedStorage")
local DayBox = RS.SkyBoxes:WaitForChild("Sunset Orange")
local NightBox = RS.SkyBoxes:WaitForChild("Dark Skies")
local Lighting = game:WaitForChild("Lighting")
--local TOD = Lighting.TimeOfDay --value is set only 1 time, therefore its kinda useless.
local Ambient = Lighting.Ambient
local OutdoorAmbient = Lighting.OutdoorAmbient
local ColorShiftTop = Lighting.ColorShift_Top
local ColorShiftBottom = Lighting.ColorShift_Bottom
local FogColor = Lighting.FogColor
local FogStart = Lighting.FogStart
local FogEnd = Lighting.FogEnd

Lighting:GetPropertyChangedSignal("TimeOfDay"):Connect(function() --runs code if it changes
local TOD = Lighting.ClockTime
if TOD >= 5.50 and TOD < 6 then -- "5:30:00" is a string because it has colons (these things : idk the name of them too :/)
    Ambient = Color3.fromRGB(0,0,255)
    OutdoorAmbient = Color3.fromRGB(0,0,127)
    ColorShiftTop = Color3.fromRGB(255,242,242)
    ColorShiftBottom = Color3.fromRGB(85,170,255)
    FogColor = Color3.fromRGB(85,170,255)
    FogStart = 100--Strings arent numbers, remove the " thingys (i dont know their names :/)
    FogEnd = 500
    --Morning
elseif TOD >= 6 and TOD < 17.50 then
    Ambient = Color3.fromRGB(255,255,0)
    OutdoorAmbient = Color3.fromRGB(255,255,0)
    ColorShiftTop = Color3.fromRGB(255,255,0)
    ColorShiftBottom = Color3.fromRGB(255,255,255)
    FogColor = Color3.fromRGB(255,255,255)
    FogStart = 250
    FogEnd = 100000
    --Sunset
elseif TOD >= 17.50 and TOD < 18 then
    Ambient = Color3.fromRGB(255,170,0)
    OutdoorAmbient = Color3.fromRGB(255,170,0)
    ColorShiftTop = Color3.fromRGB(255,170,0)
    ColorShiftBottom = Color3.fromRGB(255,255,0)
    FogColor = Color3.fromRGB(255,170,0)
    FogStart = 250
    FogEnd = 100000
    --Night
elseif TOD >= 18 then
    Lighting:WaitForChild("Sunset Orange"):Destroy()
    local NightTime = NightBox:Clone()
    NightTime.Parent = Lighting
    Ambient = Color3.fromRGB(39,76,143)
    OutdoorAmbient = Color3.fromRGB(85,0,127)
    ColorShiftTop = Color3.fromRGB(0,0,255)
    ColorShiftBottom = Color3.fromRGB(143,235,255)
    FogColor = Color3.fromRGB(85,170,255)
    FogStart = 100
    FogEnd = 500
end
end)

hope that helps

7 comments

0

Thanks Sir!

0

wait i swear i deleted this answer by it being wrong

0

by being wrong i mean they only work if you set them EXACTLY to the number described

0

Should i cange TimeOfDay to ClockTime? soit wouldn't be read as a string with "" ?

0

There. that version i made shall work. (clocktime version)

0

thanks sir, really helped making my showcase!

0

np

This discussion is preserved as it was. New answers, comments, and votes are closed.