What is wrong with this script?

At this point, I’m completely lost. I have a script in ServerScriptStorage. And here’s the code:

local Lighting = game.Lighting

if Lighting.ClockTime >= 21 or Lighting.ClockTime < 6 then
    Lighting.FogEnd = 15
else
    Lighting.FogEnd = 10000
end

I’m trying to make it so, at 6, the fog isn’t in the game, and at 9 pm - 6 am, the friend is set to 15.

Is there something I’m missing or something I’m not doing right? Any help would be very much appreciated. Thank you!

1 Like

Your code is only checking once, and that is right when the game starts. It doesn’t check again.

You will want to check each time the clock time changes using :GetPropertyChangedSignal.

local Lighting = game:GetService("Lighting") -- get services via :GetService()

Lighting:GetPropertyChangedSignal("ClockTime"):Connect(function()
    if Lighting.ClockTime >= 21 or Lighting.ClockTime < 6 then
        Lighting.FogEnd = 15
    else
        Lighting.FogEnd = 10000
    end
end)
2 Likes