Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

[SOLVED] How do I create a function that changes Atmosphere Color?

Edit: I got it working

Working script:

local function setAtmosphereColor(atmosphereColor1, atmosphereColor2, atmosphereColor3)
	local tween = TweenService:Create(Lighting.Atmosphere, TweenInfo.new(0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut), {Color = Color3.new(atmosphereColor1, atmosphereColor2, atmosphereColor3)})
	tween:Play()
end

I NEED a function that changes the atmosphere. I am trying to make a toggleable button that changes the atmosphere color. Here are my attempts and the error I got. It would mean a lot if you helped me! :D

My attempt:

local function setTimeOfDay(clockTime)
	local tween = TweenService:Create(Lighting, TweenInfo.new(0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut), { ClockTime = clockTime })
	tween:Play()
end --Works

local function setAtmosphereColor(atmosphereColor)
	local tween = TweenService:Create(Lighting.Ambient, TweenInfo.new(0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut), { Color = atmosphereColor})
	tween:Play()
end --Doesn't work

Attempt to use the function:

dock.TimeDayToggle.Day.MouseButton1Click:Connect(function()
	setTimeOfDay(12) -- Works
	setAtmosphereColor(250, 250, 250) -- Doesn't work
	dock.TimeDayToggle.Background:TweenPosition(UDim2.new(0, 0, 0, 0), "InOut", "Quad", 0.3, true)
end)

dock.TimeDayToggle.Night.MouseButton1Click:Connect(function()
	setTimeOfDay(22) -- Works
	setAtmosphereColor(20, 24, 24) -- Doesn't work
	dock.TimeDayToggle.Background:TweenPosition(UDim2.new(0.5, 0, 0, 0), "InOut", "Quad", 0.3, true)
end)

Error: Unable to cast value to Object

The error comes from the function part.

1 answer

Well, the problem, here, is you are probably trying to change the ambient property in the Lighting. Also, there is no Color property in Ambient, and that's the reason for the error.

If you are trying to change the Ambient property, you can do :

local function setAtmosphereColor(atmosphereColor)
    local tween = TweenService:Create(Lighting, TweenInfo.new(0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut), {Ambient = Color3.new(atmosphereColor)}) -- Changing the property to Lighting and not Lighting.Ambient. Also, using Color.new() to let the sytem understand that we are inputting RGB form of Color and not a double.
    tween:Play()
end

But, if you are trying to change the Color property of Atmosphere (assuming, you have Atmosphere in Lighting) :

local function setAtmosphereColor(atmosphereColor)
    local tween = TweenService:Create(Lighting.Atmosphere, TweenInfo.new(0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut), {Color = Color3.new(atmosphereColor)}) -- Changing the property to Lighting.Atmosphere. Don't forget using Color3.new().
    tween:Play()
end

NOTE : The atmosphere color change will only be noticeable, if Haze > 0, else it will look like normal.

Lemme know if it helps!

1 comment

0

The second function is what I am looking for but the problem is it only changes the first value. Instead of doing 249, 249, 249 it does 249, 0, 0. This is what I did: setAtmosphereColor(0.98, 0.98, 0.98)

This discussion is preserved as it was. New answers, comments, and votes are closed.