Designing Day/Night system

What I want to be able to do is to make a Day/Night script. Possibly a weather system intertwined with it.
I’m unsure how to make it. I know how the cycle works but the environment implementation is what I’m not too sure about, I’d assume I can use lerps or tweens. Additionally, I want to make use most of the resources available such as post processing effects and ColorShift.

Any ideas how to come across this?

2 Likes

Should actually do some research before coming here asking questions that already have millions of answers to:
https://developer.roblox.com/articles/Day-Night-Cycles-and-Street-Lights

3 Likes

Its not as advanced as I want it to be. I know the components how to make a basic script, I want to apply it more with the environment.

That link only shows how to change the time in a cycle.

2 Likes

That could be the day-night cycle you’re looking for.
On the other hand, if you want weather and more complex things. You can separate that into another system which controls weather.
In that tutorial, it shows how you can link street lights with the day and night cycle. Instead, you can try linking it up with weather such as storms and such.

Sorry if that sounded confusing but I think you might get the point?

Sorry, I didn’t make myself very clear. I understand how to do the cycle, its the implementation of these lighting effects is what I was looking for.

1 Like

Hmmm :thinking:

You could instead of linking with a street light like how it shows in the article, link it with weather like lightning.

Im also pretty sure there’s a module for lightning and rain.

1 Like

I feel like that article wouldn’t work as effectively for me.
Lighting is my biggest concern.

1 Like

Like lightning changing bricks, (if you never used those free models, you can try studying them) you can change it via finding the lighting and changing the properties by randomfying it, roblox even provides a tutorial on doing RNG :smiley: https://developer.roblox.com/articles/Random-Number-Generation

Using both that, you might be able to do that. Other than that though, I don’t really quite understand what you’re trying to do so hopefully this helps :stuck_out_tongue:

Edit: Top might sound confusing so basically, create a table where if its value 1, its stormy, if its value 2, its normal. Using RNG can randomize it to help with a more weatherly feel :3

1 Like

If changing the ambient is your biggest concern, you can always make a loop script and check the time occasionally and set the settings. Here’s how I did for the game on my beach.

local TweenService = game:GetService("TweenService")
local CycleTime = 360
local RandomStartTime = math.random(0, 24)
game.Lighting.ClockTime = RandomStartTime

local LightGoal = {}
LightGoal.ClockTime = 24
local LightStyle = TweenInfo.new(CycleTime*(RandomStartTime/24), Enum.EasingStyle.Linear, Enum.EasingDirection.Out)
TweenService:Create(game.Lighting, LightStyle, LightGoal):Play()
delay(0, function()
	game.Lighting.ClockTime = 0
	local LightGoal = {}
	LightGoal.ClockTime = 24
	local LightStyle = TweenInfo.new(CycleTime, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, -1)
	TweenService:Create(game.Lighting, LightStyle, LightGoal):Play()
end)

local CurrentDayCycle = ""
while script do
	if game.Lighting.ClockTime >= 0 and game.Lighting.ClockTime < 6 then
		if CurrentDayCycle ~= "NightTime" then
			local AmbientGoal = {}
			AmbientGoal.FogColor = Color3.fromRGB(24, 42, 63)
			AmbientGoal.FogEnd = 7000
			AmbientGoal.FogStart = 50
			AmbientGoal.OutdoorAmbient = Color3.fromRGB(107, 107, 107)
			local AmbientStyle = TweenInfo.new(2.5, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)
			TweenService:Create(game.Lighting, AmbientStyle, AmbientGoal):Play()
		end
		CurrentDayCycle = "NightTime"
	elseif game.Lighting.ClockTime >= 6 and game.Lighting.ClockTime < 6.25 then
		if CurrentDayCycle ~= "SunRise" then
			local AmbientGoal = {}
			AmbientGoal.FogColor = Color3.fromRGB(146, 163, 114)
			AmbientGoal.FogEnd = 7000
			AmbientGoal.FogStart = 600
			AmbientGoal.OutdoorAmbient = Color3.fromRGB(127, 127, 127)
			local AmbientStyle = TweenInfo.new(2.5, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)
			TweenService:Create(game.Lighting, AmbientStyle, AmbientGoal):Play()
		end
		CurrentDayCycle = "SunRise"
	elseif game.Lighting.ClockTime >= 6.25 and game.Lighting.ClockTime < 17.75 then
		if CurrentDayCycle ~= "DayTime" then
			local AmbientGoal = {}
			AmbientGoal.FogColor = Color3.fromRGB(75, 129, 191)
			AmbientGoal.FogEnd = 10000
			AmbientGoal.FogStart = 1750
			AmbientGoal.OutdoorAmbient = Color3.fromRGB(136, 136, 136)
			local AmbientStyle = TweenInfo.new(2.5, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)
			TweenService:Create(game.Lighting, AmbientStyle, AmbientGoal):Play()
		end
		CurrentDayCycle = "DayTime"
	elseif game.Lighting.ClockTime >= 17.75 and game.Lighting.ClockTime < 18 then
		if CurrentDayCycle ~= "SunSetting" then
			local AmbientGoal = {}
			AmbientGoal.FogColor = Color3.fromRGB(146, 163, 114)
			AmbientGoal.FogEnd = 7000
			AmbientGoal.FogStart = 600
			AmbientGoal.OutdoorAmbient = Color3.fromRGB(127, 127, 127)
			local AmbientStyle = TweenInfo.new(2.5, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)
			TweenService:Create(game.Lighting, AmbientStyle, AmbientGoal):Play()
		end
		CurrentDayCycle = "SunSetting"
	elseif game.Lighting.ClockTime >= 18 and game.Lighting.ClockTime <= 24 then
		if CurrentDayCycle ~= "NightTime" then
			local AmbientGoal = {}
			AmbientGoal.FogColor = Color3.fromRGB(24, 42, 63)
			AmbientGoal.FogEnd = 7000
			AmbientGoal.FogStart = 50
			AmbientGoal.OutdoorAmbient = Color3.fromRGB(107, 107, 107)
			local AmbientStyle = TweenInfo.new(2.5, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)
			TweenService:Create(game.Lighting, AmbientStyle, AmbientGoal):Play()
		end
		CurrentDayCycle = "NightTime"
	end
	wait(2.25)
end

If the current ambient settings are off, you can always adjust it.

For doing weather, you can do what 3rdhoan123 and do a RNG for when rain happens or anything else, just make sure to add a cooldown and a bool value to make sure multiple weather effects don’t happen at the same time. Just make sure to adjust the lighting again if there’s certain weather effects. If you intend to add season-times like winter and summer, you will have to specific which season it is on and to determine which weather effects can be possible.

9 Likes

Thanks for that!

Before weather and such, start with the basics:

Here we made a Day/Night script that plays with lighting aswell.

You’ll have to run the game over and over just to get your desired effects right, it will take patience, but it will be worth it.

1 Like

Thank you :slightly_smiling_face: