Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Light turning off at 18 clock time doesnt work?

Asked by 1 year ago

I wanted to make light that turns off when clock time is > 18 and turns on when clock time is > 6 but for some reason it doesnt work and i dont know why

local plight = script.Parent --point light
local light = game.Lighting -- lighting

light.Changed:Connect(function()    
    if light.ClockTime >= 18 then
        plight.Enabled = false
        print(light.ClockTime)
    end
    if light.ClockTime >= 6 then
        print(light.ClockTime)
        plight.Enabled = true
    end
end)

1 answer

Log in to vote
1
Answered by
boredlake 256 Moderation Voter
1 year ago

It's because your script is checking if light.ClockTime >= 6 after checking if light.ClockTime >= 18, meaning even though plight is disabled for a millisecond, it is enabled the next milisecond, since if it is greater than 18 then it is also greater than 6. The fix is simple - rather than putting end and starting a new if-statement, just use elseif as replacement.

Ad

Answer this question