Fog Script issue [ROBLOX ISSUE]

My fog code is kinda not working for more information view the video below:
robloxapp-20221217-2237583.wmv (1.1 MB)

And here is the code:

-- Declare variables for the length of the day and night cycles
local dayLength = 150
local nightLength = 500

-- Create variables to track the current fog density and fade rate
local fogDensity = 0
local fogFadeRate = 0

-- Create a boolean variable to track whether it is currently day or night
local isDay = true

-- Create a timer to switch between day and night
local switchTimer = game:GetService("RunService").Stepped:Connect(function()
	-- Decrement the length of the current cycle
	if isDay then
		dayLength = dayLength - 1
	else
		nightLength = nightLength - 1
	end
	
	-- If the current cycle has ended, switch to the other cycle and reset the timer
	if dayLength <= 0 then
		isDay = false
		dayLength = 150
	elseif nightLength <= 0 then
		isDay = true
		nightLength = 500
	end
	
	-- Update the skybox and lighting based on the current cycle
	if isDay then
		game.Lighting.TimeOfDay = 0
		game.Lighting.FogColor = Color3.new(0.8, 0.8, 0.8)
		game.Lighting.OutdoorAmbient = Color3.new(0.6, 0.6, 0.6)
		
		-- Slowly decrease the fog density
		fogDensity = math.max(fogDensity - 0.01, 0)
		fogFadeRate = -0.01
	else
		game.Lighting.TimeOfDay = 0.5
		game.Lighting.FogColor = Color3.new(0.2, 0.2, 0.2)
		game.Lighting.OutdoorAmbient = Color3.new(0.1, 0.1, 0.1)
		
		-- Slowly increase the fog density
		fogDensity = math.min(fogDensity + 0.01, 1)
		fogFadeRate = 0.01
	end
	
	-- Update the fog density
	game.Lighting.FogEnd = 100 + fogDensity * 200
end)

So mind anyone helping me?

1 Like

Fog doesn’t work if lighting contains an Atmosphere.

1 Like

DayLength and NightLength are both less than 0 so this statement will always return true.

1 Like

The lightning contains no atmosphere.

So basically I am too dumb to fix that so mind helping me out or give me an explanation on how to fix that?

No that part was fine, I don’t know why bro thought there was an issue there.

1 Like

It might just be going too fast then. Maybe tweening the fog will help? Or maybe it’s the TimeOfDay you set since it’s not a string:

A number does not need to be a string as it is an integer. I have figured out that maybe this can help:

if dayLength <= 0 or nightLength <= 0 then
  if dayLength <= 0 then
    isDay = false
    dayLength = 150
  elseif nightLength <= 0 then
    isDay = true
    nightLength = 500
  end
end

This isn’t the problem, my bad. It’s probably since TimeOfDay is a string and not a number.

though TimeOfDay is a number, also not the issue.

1 Like

Does it have something to do with the ROBLOX light engine going crazy again?

TimeOfDay is a string, ClockTime is a number.

Even tho I converted the number to a string now still doesn’t seem to fix it. The problem actually still occurs.

I’m literally in studio right now, freely able to set the TimeOfDay to a number in the command bar and in a local script. It’s a number.

1 Like

Change TimeOfDay to ClockTime.

This still did not fix it. The fog is doing the same thing as shown in the video.

set script run context to Server xd

I am and it still doesn’t work.

It is an ROBLOX based lightning error.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.