How to change Clouds And Fog at a Certain Time

Hello,

I have been trying to do this for a lot of time,
I have looked for Tutorials, I even made my own script. Nothing Worked.

The help i need is:
When the game hits a time like 6 AM

  • There will be Fog where you can’t see
  • The Clouds will be White.

When the game hits a time like 8 PM

  • The Clouds will change color to Grey / Black

If someone can help me and send a script, i can do it further with the help.

Sincerely,
Milk

I’m assuming you have a script to change the time progressively, it depends on exactly how time is changing, but you can access the time of day via game.Lighting.ClockTime (which is in military time).

So, maybe you could do a check every couple of seconds or so to see if the ClockTime is within a certain range (as checking for an exact number might not work if it moves in small increments).

As an example:

local weatherState = 0

while true do
	local clockTime = Lighting.ClockTime

	if (clockTime > 5.5 and clockTime < 6.5) and weatherState ~= 6 then
		weatherState = 6
		-- do things
	end

	task.wait(2)
end

This will do an action if the clock time is around 6 AM, though keep in mind you may want to somehow fit this into a function to easily add actions to it. Also, maybe save the current state of weather or whatnot so it doesn’t repeat actions constantly (edited the code snippet to include this kind of functionality)

1 Like

It worked, Thank you so much!!!

I just have 1 more question,

When i join the game, its not working cause i have to wait until the certain time, How do i fix this?

So it works fine, you just want to start with a certain weather?
Then just set the weather when the server first loads :person_shrugging:

if game:GetService(“RunService”):IsStudio() then
– your studio test logic
end

is your friend. With this, you can make test conditions and not worry about removing/commenting them when publishing the game over and over again

No, I mean, When the time hits 18, It changes the fog.

But when you join a new game and its 18.1, it does not change fog, i then have to wait until it hits 18.

Increase the range then… that’s what the greater than and lesser than operators are for

clockTime > 17 and clocktime < 19

Don’t use clockTime > 17 and clocktime < 19 because that only checks if it’s within that range.
Use

while task.wait(10) do --you don't need this script to be really precise do you?
    if clockTime > 18 then 
        --set your lighting parameters for night
    elseif clockTime > 6
        --set your lighting parameters for day
    end
end

There are also many many posts about day/night cycles, and some about changing the lighting parameters like: A Guide to a Better Looking and More Realistic Day/Night Cycle

1 Like

I won’t, cause then it won’t be realistic.

And i have Real Time, so when its 2 PM in real life in 2PM ingame.

ooh that is a better way to do it