Fog color - How to change?

I need white fog at bay and black fog at night image

local oh,om = 5,50	-- Open Time (hours,minutes)
local ch,cm = 18,50	-- Close Time (hours, minutes)

local l = game:service("Lighting")
if (om == nil) then om = 0 end
if (cm == nil) then cm = 0 end


function TimeChanged()
	local ot = (oh + (om/60)) * 60
	local ct = (ch + (cm/60)) * 60
	if (ot < ct) then
		if (l:GetMinutesAfterMidnight() >= ot) and (l:GetMinutesAfterMidnight() <= ct) then
			script.Parent.FogColor = script.Black
		else
			script.Parent.FogColor = script.White
		end
	elseif (ot > ct) then
		if (l:GetMinutesAfterMidnight() >= ot) or (l:GetMinutesAfterMidnight() <= ct) then
			script.Parent.FogColor = script.Black
		else
			script.Parent.FogColor = script.White
		end
	end
end

TimeChanged()
game.Lighting.Changed:connect(function(property)
			if (property == "TimeOfDay") then
				TimeChanged()
			end
		end)

-- Ganondude
1 Like

script.Parent.FogColor = script.Black
else
script.Parent.FogColor = script.White

I think your problem is that you are referencing the “White” and “Black” object, not their values.

Here’s a fixed version:

local oh,om = 5,50	-- Open Time (hours,minutes)
local ch,cm = 18,50	-- Close Time (hours, minutes)

local l = game:service("Lighting")
if (om == nil) then om = 0 end
if (cm == nil) then cm = 0 end


function TimeChanged()
	local ot = (oh + (om/60)) * 60
	local ct = (ch + (cm/60)) * 60
	if (ot < ct) then
		if (l:GetMinutesAfterMidnight() >= ot) and (l:GetMinutesAfterMidnight() <= ct) then
			script.Parent.FogColor = script.Black.Value --here is your mistake
		else
			script.Parent.FogColor = script.White.Value --you should reference the value, not the object
		end
	elseif (ot > ct) then
		if (l:GetMinutesAfterMidnight() >= ot) or (l:GetMinutesAfterMidnight() <= ct) then
			script.Parent.FogColor = script.Black.Value --add it here aswell
		else
			script.Parent.FogColor = script.White.Value --and add it here too
		end
	end
end

Also, if that doesn’t work, then make sure the “White” and “Black” are Color3 Values.

2 Likes

Scripts cannot be executed from Lighting. Place it in ServerScriptService and recode it according to the new location.

2 Likes