So, I’m trying to make a street lamp that detects when it’s daytime or nighttime. So, when it’s daytime, it turns off and when it’s nighttime it turns on. Now, bear with me. I am a terrible scripter and my script may be very horrid. This is what I did:
local light = script.Parent
local lightsource1 = light.PointLight
local lightsource2 = light.SpotLight
local timeofday = game.Lighting.ClockTime
if timeofday == 17.6 then
lightsource1.Enabled = true
lightsource2.Enabled = true
else if timeofday == 6.3 then
lightsource1.Enabled = false
lightsource2.Enabled = false
end
end
For some reason, it does not work and it can be a very idiotic issue that I did not notice. Can anyone help, please?
you have got the variable ClockTime and stored it to another variable, I understand how you got confused but thats not how variables work, you arent storing the variable you are storing what the value of ClockTime was at the time which wont help
local light = script.Parent
local lightsource1 = light.PointLight
local lightsource2 = light.SpotLight
local lighting = game.Lighting
if lighting.ClockTime == 17.6 then
lightsource1.Enabled = true
lightsource2.Enabled = true
else if lighting.ClockTime == 6.3 then
lightsource1.Enabled = false
lightsource2.Enabled = false
end
end
I just discovered a problem. Since my daycycle script does not specifically go on those values, the lights won’t do anything. I’ve been trying to temper around like… greater then or less then symbols, whatever. Still no use…
local light = script.Parent
local lightsource1 = light.PointLight
local lightsource2 = light.SpotLight
local lighting = game.Lighting
if lighting.ClockTime < 17.6 then
lightsource1.Enabled = false
lightsource2.Enabled = false
else if lighting.ClockTime > 17.6 then
lightsource1.Enabled = true
lightsource2.Enabled = true
if lighting.ClockTime < 6.3 then
lightsource1.Enabled = true
lightsource2.Enabled = true
else if lighting.ClockTime > 6.3 then
lightsource1.Enabled = false
lightsource2.Enabled = false
end
end
end
end
local light = script.Parent
local lightsource1 = light.PointLight
local lightsource2 = light.SpotLight
local lighting = game.Lighting
lighting:GetPropertyChangedSignal("ClockTime"):Connect(function()
if lighting.ClockTime >= 17.6 or lighting.ClockTime <= 6.3 then
lightsource1.Enabled = true
lightsource2.Enabled = true
end
end)
So, I fixed it up a bit because you forgot to state when it turns off. I’m still giving you the solution. This is the finalized script:
local light = script.Parent
local lightsource1 = light.PointLight
local lightsource2 = light.SpotLight
local lighting = game.Lighting
lighting:GetPropertyChangedSignal("ClockTime"):Connect(function()
if lighting.ClockTime >= 17.6 or lighting.ClockTime <= 6.3 then
lightsource1.Enabled = true
lightsource2.Enabled = true
else if lighting.ClockTime <= 17.6 or lighting.Clocktime >=6.3 then
lightsource1.Enabled = false
lightsource2.Enabled = false
end
end
end)
I still would like to give you the solution because I used the same method you did but gave it the opposite ‘Greater than, Less than’ state.