OutdoorAmbient/Fogcolor Script

Update: The script works now, the script written below works 100%. If anyone wants a script that gradually changes the OutdoorAmbient and FogColor at different times of the day, the scripter who made this script is asomeman108. He says you are welcome to use it if you need it for your game.

local ambistart = Color3.new(1, 0.922, 0.827)
local ambifinish = Color3.new(0.094, 0.094, 0.094)
local fogcolorstart = Color3.new(0.784, 0.706, 0.569)
local fogcolorfinish = Color3.new(0.082, 0.082, 0.082)

darkout = false

while true do
	wait(2)
	if game.Lighting.ClockTime >= 17 or game.Lighting.ClockTime <= 6.5 then
		if darkout == false then
			print("darkening")
			for i = 0, 1, 0.00227 do
    			game.Lighting.OutdoorAmbient = ambistart:Lerp(ambifinish, i)
    			game.Lighting.FogColor = fogcolorstart:Lerp(fogcolorfinish, i)
    			wait(0.1)
    		end
    		darkout = true
    	end
	elseif game.lighting.ClockTime <= 17 and game.lighting.ClockTime >= 6.5 then
    	if darkout == true then
	    	print("lightening")
	    	for i = 0, 1, 0.00227 do
		    	game.Lighting.OutdoorAmbient = ambifinish:Lerp(ambistart, i)
		    	game.Lighting.FogColor = fogcolorfinish:Lerp(fogcolorstart, i)
		    	wait(0.1)
	    	end
	    	darkout = false
	    end
     end
 end

Thank you very much.

3 Likes

You’re trying to get to 0.4795 with 0.525 by adding 0.425. You would do 0.525, 0.4795, -0.425 instead.

Didn’t work. It turned the fogcolor and outdoorambient ridiculously high.

98a6dbaf28d4cf3eb9b7498528fc479b
dc98435f84a6827bf26254d75bac39d4

Why are you using a for loop with 3 decimals anyways? It will always output the same thing if you’re just lerping to decimals. Also, you need to use Color3.fromRGB as that returns the correct Color3 values.

My friend is asking what alpha does on Lerp for Color3.

It lerps to a certain alpha in a thing. For example, if you wanted to lerp 1 to 0 you would do a:Lerp(0, 1)

Thanks. Also,

Are we not supposed to use decimals? Should we use whole numbers?

My friend said that there’s three digits here, and your example uses two.

I’m asking why are you using a for loop with 3 decimals. You’re trying to use a for loop to lerp decimals (keep in mind it’s being lerped from a preset value) and it always returns the same thing instead of gradually lerping, like you want.

Also what do you mean by 3 digits? Lerping is always the same, whether it be a CFrame, Vector3, or Color3.


He is asking what the alpha (the i at the end) means. He doesn’t know what the three separate numbers do and thus doesn’t know why he can’t have decimal values.

The first number is the current number you have. The second number is the goal you’re trying to reach. The third number is the value you’re adding/subtracting by.

You could use tween service to tween the lighting to the desired values.

local ts = game:GetService("TweenService")
local nightTween = ts:Create(game.Lighting, TweenInfo.new(1), {
	["OutdoorAmbient"] = Color3.fromRGB(Color3.fromRGB(255, 235, 211)),
	["FogColor"] = Color3.fromRGB(200, 180, 145)
})
nightTween:Play()

The code that I posted only changes it to the night time. If you haven’t heard of TweenService, here’s the wikipedia page.

This would gradually lower the OutdoorAmbient and FogColor?


This is what the current script does to the lighting. The values are currently

for i = 0, 1, 0.00227 do

Color3.new(r, g, b) uses values between 0 and 1 for the R/G/B components. If you want to use values between 0 and 255 instead, use Color3.fromRGB(r, g, b).

Alternatively, continue using Color3.new(r, g, b), but divide the R/G/B values by 255.

We’re already doing that, that’s not the problem. At this point it’s just the math. I’ve updated the script at the top of the post.

Yes it is the problem. If by updated code you mean the code in the OP is updated, you are still using the new constructor with values greater than 1, right at the top of your script.

The fundamental issue of which Color3 constructors you’re using for what purposes needs to be addressed first before you can start isolating any other issues.

So the Color3 values should be less than 1? I don’t understand.

If you are using the new constructor, yes, each value must be 0 ≤ n ≤ 1. The values passed to a Color3 object depend on what constructor you are using. If it is new, it is between 0 and 1. Any value higher than that will cause unnaturally high values to be applied. You are using Color3.new with values >1 when you should either be dividing those all by 255 or using fromRGB.

This was explained in the post you replied to and said it’s not the problem. It is the problem.

Thank you very much! This made the script work!

If anyone needs this script, the scripter who made this, asomeman108, has graciously allowed any who need this to use it. Posted the working script at the top of the page if anyone needs it.

Note if you want to use this script, you should probably tweak the time values and the OutdoorAmbient values. Take the value of the outdoor ambient (should be 3 numbers) and divide each by 255 to replace vals.