In need of a script that changes fog colour during different time periods (10:00 - 14:00)

Hello! I am in need of a script that changes the Fog colour during certain time periods. This is to create a render distance effect. Here’s what 4 different times look like when the fog is white (why I want to change the fog at different times):

Ignore the Time gui, it isn’t accurate :slight_smile:

Feedback

If you didn’t want players to see out of the map, you could adopt something similar to SharkBite :shark: and and a physical barrier or just increase the waters so far as they could not see the end (with an invisible wall).

As Dominus said, you could just increase the size of the water, but it would decrease the performance. I would suggest adding blocks with slight transparency, so it creates a fog like effect.

Couldn’t I just use the fog then? During daytime using fog is fine, since the white blends in, but during night time the white line looks odd.

Well, it is supposed to be an island in the middle of nowhere, surely there’s some sort of way?

Then add a script that changes the color during night time, that should be simple.

1 Like

Why don’t you search on the forum^^ Im sure you’ll find some help. It would not be a complicated script

1 Like

Here i came up with a simple script. Put it into a script in the blocks. You may need to adjust the colors and times tho.

while true do

if game.Lighting.TimeOfDay = "6:00:00" then -- Daytime

script.Parent.BrickColor = BrickColor.new("White") else

if game.Lighting.TimeOfDay = "19:00:00" then -- Nighttime

script.Parent.BrickColor = BrickColor.new("Black")

end

I just figured that out, and know how to change it:
`while true do

if game.Lighting.TimeOfDay = “6:00:00” then – Daytime

script.Parent.BrickColor = BrickColor.new(“White”) else

if game.Lighting.TimeOfDay = “19:00:00” then – Nighttime

script.Parent.BrickColor = BrickColor.new(“Black”)

end`

That’s not a script for brick mate. The script makes using color simply. Put the script in a brick and set the color of the brick with the color of fog you want.

I just figured that out, and know how to change it:

while true do

if game.Lighting.TimeOfDay = "6:00:00" then -- Daytime

script.Parent.BrickColor = BrickColor.new("White") else

if game.Lighting.TimeOfDay = "19:00:00" then -- Nighttime

script.Parent.BrickColor = BrickColor.new("Black")

end

But I still need more options than just night and day? Also more colour options would be nice. (Colour hex)

Also will it be in a local script or a script?

You can grab the best colour for each time and then interpolate between. I have a function for it in my.own game, however it has slightly different lighting to the default so the colours won’t necessarily match yours perfectly.

The best thing you can do is set the clock to some key times where the colour starts and finishes changing and record the best colour that matches it. Particularly during sunrise as the sky changes colour a couple of times. Sunset is easier as it goes orange, purple, black.

I’ll grab the code for you when I next get chance.

2 Likes

Thanks very much :slight_smile: I thought so, I can just change the colours. Just tell me when you have it, thank you :smiley:

In future, the best thing you can do is to give it a try yourself and post a topic in #help-and-feedback:scripting-support, as you will find better help and working code snippets there. The code snippets in this topic are full of syntax and logical errors, but I can see you’ve given it a go so I’m happy to share this with you:

local Lighting = game:GetService( 'Lighting' )

local FOG_COLOURS = {
	[ 'black' ] = Color3.new( 0, 0, 0 ),
	[ 'dark_blue' ] = Color3.fromRGB( 34, 40, 58 ),
	[ 'early_orange' ] = Color3.fromRGB( 69, 60, 62 ),
	[ 'early_purple' ] = Color3.fromRGB( 52, 41, 63 ),
	[ 'light_blue' ] = Color3.fromRGB( 180, 210, 228 ),
	[ 'late_orange' ] = Color3.fromRGB( 72, 61, 42 ),
	[ 'late_purple' ] = Color3.fromRGB( 50, 38, 63 ),
}

function getFogColour( minutes )
	if type( minutes ) ~= 'number' then
		return FOG_COLOURS.light_blue
	end
	
	local hours = minutes / 60
	
	if hours <= 3 or hours >= 21 then
		return FOG_COLOURS.black
	elseif hours > 3 and hours <= 4 then
		return FOG_COLOURS.black:lerp( FOG_COLOURS.dark_blue, hours - 3 )
	elseif hours > 4 and hours <= 5.5 then
		return FOG_COLOURS.dark_blue:lerp( FOG_COLOURS.early_orange, ( hours - 4 ) / 1.5 )
	elseif hours > 5.5 and hours <= 6 then
		return FOG_COLOURS.early_orange:lerp( FOG_COLOURS.early_purple, ( hours - 5.5 ) / 0.5 )
	elseif hours > 6 and hours <= 6.5 then
		return FOG_COLOURS.early_purple:lerp( FOG_COLOURS.light_blue, ( hours - 6 ) / 0.5 )
	elseif hours > 6.5 and hours <= 17.5 then
		return FOG_COLOURS.light_blue
	elseif hours > 17.5 and hours <= 18 then
		return FOG_COLOURS.light_blue:lerp( FOG_COLOURS.late_orange, ( hours - 17.5 ) / 0.5 )
	elseif hours > 18 and hours <= 18.4 then
		return FOG_COLOURS.late_orange:lerp( FOG_COLOURS.late_purple, ( hours - 18 ) / 0.4 )
	elseif hours > 18.4 and hours <= 20 then
		return FOG_COLOURS.late_purple
	elseif hours > 20 and hours <= 21 then
		return FOG_COLOURS.late_purple:lerp( FOG_COLOURS.black, hours - 20 )
	end
end

Lighting:GetPropertyChangedSignal( 'TimeOfDay' ):Connect( function()
	local minutes = Lighting:GetMinutesAfterMidnight()
	Lighting.FogColor = getFogColour( minutes )
end )

I’ve had a quick test and these colours do actually seem to match the default really closely. If there are any that are slightly off, you should be able to swap the colours after a bit of experimentation. I needed the fog colour to match the sky really closely in my game which is why it’s split into loads of different conditions based on the time in hours to get it as accurate as possible.

Let me know if you struggle to get the colours and I’ll try to help.

5 Likes

Thank you so very much! Will try it :smiley:

No problem. If it works for you, hit “Solution” on the reply :slight_smile:

1 Like

Hmm, didn’t work, but no errors? Where do I place it? Local script or script?

LocalScript is where it was for me, but shouldn’t make too much difference. Best to keep it on the client anyway.

Pop it in a LocalScript in ReplicatedFirst and it should work fine. I tested it before sending. You’ll need to change the time in Lighting using another script or manually to see the effect.

1 Like

SUCCESS! Works like a charm, thank you so much! KIT, when I actually have Robux I’ll pay you 500 (or more idk bad at pricing) :slight_smile: now to find out how to make it darker at night :slight_smile:

Day time outdoor ambient colour: #6d6d6d

Night time outdoor ambient colour: #2a2a2a

local Lighting = game:GetService( 'Lighting' )

local FOG_COLOURS = {
	[ 'black' ] = Color3.new( 0, 0, 0 ),
	[ 'dark_blue' ] = Color3.fromRGB( 34, 40, 58 ),
	[ 'early_orange' ] = Color3.fromRGB( 69, 60, 62 ),
	[ 'early_purple' ] = Color3.fromRGB( 52, 41, 63 ),
	[ 'light_blue' ] = Color3.fromRGB( 180, 210, 228 ),
	[ 'late_orange' ] = Color3.fromRGB( 72, 61, 42 ),
	[ 'late_purple' ] = Color3.fromRGB( 50, 38, 63 ),
}

local OUTDOOR_AMBIENTS = {
	[ 'daytime' ] = Color3.fromRGB( 109, 109, 109 ),
	[ 'sunset' ] = Color3.fromRGB( 62, 62, 62 ),
	[ 'midnight' ] = Color3.fromRGB( 42, 42, 42 ),
}

function getFogColour( minutes )
	if type( minutes ) ~= 'number' then
		return FOG_COLOURS.light_blue
	end
	
	local hours = minutes / 60
	
	if hours <= 3 or hours >= 21 then
		return FOG_COLOURS.black
	elseif hours > 3 and hours <= 4 then
		return FOG_COLOURS.black:lerp( FOG_COLOURS.dark_blue, hours - 3 )
	elseif hours > 4 and hours <= 5.5 then
		return FOG_COLOURS.dark_blue:lerp( FOG_COLOURS.early_orange, ( hours - 4 ) / 1.5 )
	elseif hours > 5.5 and hours <= 6 then
		return FOG_COLOURS.early_orange:lerp( FOG_COLOURS.early_purple, ( hours - 5.5 ) / 0.5 )
	elseif hours > 6 and hours <= 6.5 then
		return FOG_COLOURS.early_purple:lerp( FOG_COLOURS.light_blue, ( hours - 6 ) / 0.5 )
	elseif hours > 6.5 and hours <= 17.5 then
		return FOG_COLOURS.light_blue
	elseif hours > 17.5 and hours <= 18 then
		return FOG_COLOURS.light_blue:lerp( FOG_COLOURS.late_orange, ( hours - 17.5 ) / 0.5 )
	elseif hours > 18 and hours <= 18.4 then
		return FOG_COLOURS.late_orange:lerp( FOG_COLOURS.late_purple, ( hours - 18 ) / 0.4 )
	elseif hours > 18.4 and hours <= 20 then
		return FOG_COLOURS.late_purple
	elseif hours > 20 and hours <= 21 then
		return FOG_COLOURS.late_purple:lerp( FOG_COLOURS.black, hours - 20 )
	end
end

Lighting:GetPropertyChangedSignal( 'TimeOfDay' ):Connect( function()
	local minutes = Lighting:GetMinutesAfterMidnight()
	Lighting.FogColor = getFogColour( minutes )
end )

Code I am working on :smiley: tell me if there’s an error and I’ll fix it :slight_smile:

Hey, I’m stuck, what do I do next?