Ok so, though you could loop through forever to do this that is not as performance friendly as just detecting when the time changes using GetPropertyChangedSignal which will detect when the time changes and do whatever it is you want to be done accordingly.
Here is a fix for your code using GetPropertyChangedSignal I also changed your conditional statements from == to >=. It might be worth taking the time to set a variable for if the lights are already turned on so that each clock change isn't trying to set the materials and pointlights to what they already are.
local Light1 = script.Parent.Light1
local Light2 = script.Parent.Light2
local Lighting = game:GetService("Lighting")
local function timeChanged()
if Lighting.ClockTime >= 18 then
Light1.Material = Enum.Material.Neon
Light2.Material = Enum.Material.Neon
Light1.PointLight.Enabled = true
Light2.PointLight.Enabled = true
elseif Lighting.ClockTime >= 6 then
Light1.Material = Enum.Material.SmoothPlastic
Light2.Material = Enum.Material.SmoothPlastic
Light1.PointLight.Enabled = false
Light2.PointLight.Enabled = false
end
end
Lighting:GetPropertyChangedSignal("ClockTime"):Connect(timeChanged)
Keep in mind for this code to work changing the slider in studio wont effect anything, you need to have a script in game manually changing your clocktime for this to be effective. I have included one below for testing the script, this one is extremely fast and if you want to use it I would advise lowering the rate of change.
while wait(0.1) do
game.Lighting.ClockTime = game.Lighting.ClockTime + 0.1
end
1 comment
Also, I used a script to make this.