Why doesn't this work

Im trying to make a script that between 5am and 6pm the atmosphere density is set at 0.4 and between 6pm and 5 am the atmosphere density is at 0.8
when i change the time it doesnt change the fog

ctime = game.Lighting.ClockTime

while true do
	if ctime >= 5 or ctime <= 18  then
		game.Lighting.Atmosphere.Density = 0.4
		print("lowfog")
	elseif ctime < 5 or ctime > 18  then
		game.Lighting.Atmosphere.Density = 0.8
		print("highfog")
	end
	wait(0.01)
end

u set the time as a value

ctime = game.Lighting.ClockTime -- if set at 6 will print 6 only

which means it will remain the same even after u change it

to fix your issue u should do this

ctime = game.Lighting

while true do
	if ctime.ClockTime >= 5 or ctime.ClockTime <= 18  then
		game.Lighting.Atmosphere.Density = 0.4
		print("lowfog")
	elseif ctime.ClockTime< 5 or ctime.ClockTime > 18  then
		game.Lighting.Atmosphere.Density = 0.8
		print("highfog")
	end
	wait(0.01)
end

Still doesn’t work when i change time it still prints lowfog

ups my bad

here it is

ctime = game.Lighting

while true do
	if ctime.ClockTime >= 5 and ctime.ClockTime <= 18  then
		game.Lighting.Atmosphere.Density = 0.4
		print("lowfog")
	else
		game.Lighting.Atmosphere.Density = 0.8
		print("highfog")
	end
	wait(0.01)
end

still not working when i change the time

i just tried it out it should work
try setting it to 4

what do i need to set to 4 3O chrrsssss

if you are changing the time on the client, and this runs on the server it won’t work

also don’t use a loop for this

local Lightning = game:GetService("Lightning")

function CheckClockTime()
    if Lightning.ClockTime >= 5 and Lightning.ClockTime <= 18  then
        Lighting.Atmosphere.Density = 0.4
        print("lowfog")
    else
        Lighting.Atmosphere.Density = 0.8
        print("highfog")
    end
end

Lightning:GetPropertyChangedSignal("ClockTime"):Connect(CheckClockTime)
CheckClockTime()
2 Likes

Nevermind it works but how would i make that it fades from 0.8 to 0.4

1 Like

you could use tweenservice

local Lightning = game:GetService("Lightning")
local TweenService = game:GetService("TweenService")

local Time = 1

function TweenDensity(Value)
    TweenService:Create(Lightning.Atmosphere, TweenInfo.new(Time), {
        Density = Value
    }):Play()
end

function CheckClockTime()
    if Lightning.ClockTime >= 5 and Lightning.ClockTime <= 18 then
        TweenDensity(0.4)
        print("lowfog")
    else
        TweenDensity(0.8)
        print("highfog")
    end
end

Lightning:GetPropertyChangedSignal("ClockTime"):Connect(CheckClockTime)
CheckClockTime()

just set Time to how long you want the fade to take