A hazy shade of winter... and I want to control haze!

Hi there, I want to set the Lighting.Atmosphere.Haze level in a local script. But once I set it to a non-zero number via the script, it won’t change thereafter i.e. I can change it from a default value of 2 to 0 and that works. Then I change it back to 2 (in script) and it won’t go back to 0 after that.

Here’s my script:

local ReplicatedStorage	= game:GetService("ReplicatedStorage")
local LightingSvc			= game:GetService("Lighting")

local SpaceSky				= ReplicatedStorage:WaitForChild("Lighting"):WaitForChild("SpaceSky")
local StandardSky			= ReplicatedStorage:WaitForChild("Lighting"):WaitForChild("StandardSky")

local DEFAULT_NAME = "Sky"

local Lighting = {}

--
-- Change to space lighting
--
function Lighting.toSpace()
	LightingSvc.Sky:Destroy()
	LightingSvc.Atmosphere.Haze = 0
	LightingSvc.ClockTime = 6.3

	local clone = SpaceSky:Clone()
	clone.Parent = LightingSvc
	clone.Name = DEFAULT_NAME
end

--
-- Change to default lighting
--
function Lighting.toDefault()
	LightingSvc.Sky:Destroy()
	LightingSvc.Atmosphere.Haze = 2
	LightingSvc.ClockTime = 14.5

	local clone = StandardSky:Clone()
	clone.Parent = LightingSvc
	clone.Name = DEFAULT_NAME
end

return Lighting

So for example, if the workspace.Lighting.Atmosphere.Haze is set to 2 before I run in studio, I start the game and call Lighting.toSpace() that works - there is no haze.

Later, I call Lighting.toDefault() and that works too - there IS haze.

Later, I call Lighting.toSpace() again and that does not work - there is still haze.

Any idea what I’m missing?

FWIW, I read the docs and looked for answers on the forums but it seems pretty straightforward in the docs and couldn’t find many posts, or any relevant, about haze on the forums.

Your client side module to change the the Lighting properties works normally, probably you are not calling it, or different local scripts are changing the properties too. I did run this test using your module, and I created a local script that calls your module functions on a loop, from toSpace to toDefault each 3 seconds.

Everytime the module is called, the Haze change from 0 to 2 and goes back to 0, the Sky is replaced, and the Clock time changed, everything seems working normally.

a local script in CharacterScripts:

local Lighting = require(script.Parent:WaitForChild("Lighting"))

local Tester = true

while true do
	if Tester then
		Lighting.toSpace()
		Tester = false
	else
		Lighting.toDefault()
		Tester = true		
	end
	wait(3)
end

your client module in CharacterScripts:

local ReplicatedStorage	= game:GetService("ReplicatedStorage")
local LightingSvc = game:GetService("Lighting")

local SpaceSky = ReplicatedStorage:WaitForChild("Lighting"):WaitForChild("SpaceSky")
local StandardSky = ReplicatedStorage:WaitForChild("Lighting"):WaitForChild("StandardSky")

local DEFAULT_NAME = "Sky"

local Lighting = {}

-- Change to space lighting
function Lighting.toSpace()
	warn("toSpace")
	LightingSvc.Sky:Destroy()
	LightingSvc.Atmosphere.Haze = 0
	LightingSvc.ClockTime = 6.3

	local clone = SpaceSky:Clone()
	clone.Parent = LightingSvc
	clone.Name = DEFAULT_NAME
end

-- Change to default lighting
function Lighting.toDefault()
	warn("toDefault")
	LightingSvc.Sky:Destroy()
	LightingSvc.Atmosphere.Haze = 2
	LightingSvc.ClockTime = 14.5

	local clone = StandardSky:Clone()
	clone.Parent = LightingSvc
	clone.Name = DEFAULT_NAME
end

return Lighting

Thanks for testing that! I’m confident it is being called, and set when I expect (confirmed via output). I’m new to Roblox - I’m also confident I’ve never written any code to change the atmosphere in any way :slight_smile:

That said, obviously we have conflicting results so something is different. I went to test in a fresh place to eliminate other script variables but looks like Roblox service is down/struggling so I’ll get to it later and let you know what I find!

Looks like you’re right - I created an empty project with a minimal implementation to reproduce (a bit more code than what you have just because I’m using a teleport event to invoke the lighting change) but didn’t have a problem in the new project.

Still not sure what is wrong in the original - searching through code and there just isn’t anything to find there that is setting anything to do with lighting or atmosphere so still a mystery what is up.

User error… in the primary game, my teleporting is necessarily a bit complicated and I’d been calling ONE lighting change server-side, inadvertently. Fixing that solved the problem.

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