I have a surface light inside a part that is enabled at all times. I’m looking for a way to where after a certain time of day, the light will change color and change brightness, and then after another few hours have passes, AKA when morning comes, the lights revert back to their starting color.
if you mean in-game times, here is some code. you need to change the variables’ values in-order for this to work
local lightPart = [lightpart here] -- put your light part here(the part, not the light)
local light = [light source] --put your source: like a pointlight or spotlight
local lighting = game:GetService("Lighting")
local startTime = [start time] --when the light changes brightness and other stuff
local endTime = [revert time] -- when the light reverts
lighting:GetPropertyChangedSignal("ClockTime"):Connect(function()
if lighting.ClockTime >= startTime and lighting.ClockTime < endTime then
-- change properties here
else
-- revert properties here
end
end)
tell me if it works
Hi!
You’re missing a trigger-debounce, to make sure that the time only changes once, when it’s between a certain ClockTime, we wouldn’t want to try and change properties more than once, when it’s not needed.
local lightPart = [lightpart here] -- put your light part here(the part, not the light)
local light = [light source] --put your source: like a pointlight or spotlight
local lighting = game:GetService("Lighting")
local NightPropertiesSet = false
local DayPropertiesSet = false
local startTime = [start time] --when the light changes brightness and other stuff
local endTime = [revert time] -- when the light reverts
lighting:GetPropertyChangedSignal("ClockTime"):Connect(function()
if lighting.ClockTime >= startTime and lighting.ClockTime < endTime then
if not DayPropertiesSet then
DayPropertiesSet = true
NightPropertiesSet = false
-- set day properties here
end
else
if not NightPropertiesSet then
NightPropertiesSet = true
DayPropertiesSet = false
-- set night properties here
end
end
end)
Might be able to modify this to do so.
Adding onto this, I don’t recommend using while loops in a server script. You should handle all of this on the client, and use task.wait() as wait() is deprecated.
This is too conflicting in my game because I already have enough parts and lights so changing the names and then changing the variable name would be too difficult, also I do not have the singlest idea as to where to put this script. I was looking for a script that i could paste into the actual SurfaceLight and have it change color and brightness depending on the time of day, specifically getting dimmer after 8pm and returning to normal at 7am.
You should not put a script into each surfacelight or so, this will cause more performance issues than the method I’ve shown above.
What you should do is making 1 “MainScript” for the day/night change-system, and then loop through all the object/values that you want changed.
I know, It’s just an old tutorial! I also would use property getchangedsignal
you can loop through all the dtreetlights and run the code on each one