Cloud Script Help (easy one_)

I am trying to make a script that makes it cloudy at a certain time of day in the game. This is what I have so far in serverscriptsevice. But it acts like it cant adjust the cloud cover.


local Lighting = game:GetService("Lighting")
local Workspace = game:GetService("Workspace")

-- Define the times of day for your changes
local cloudyTime = 12 * 60 + 30 -- 12:30
local clearTime = 15 * 60 + 10 -- 15:10

-- Function to update cloud cover based on time
local function updateCloudCover()
	local currentTime = Lighting.ClockTime

	if currentTime >= cloudyTime and currentTime < clearTime then
		-- It's cloudy time, set cloud cover to 0.8
		Workspace.Terrain.Clouds.Cover = 0.8
	else
		-- It's clear time, set cloud cover to 0.5
		Workspace.Terrain.Clouds.Cover = 0.5
	end
end

-- Connect the update function to run when the Lighting's ClockTime changes
Lighting:GetPropertyChangedSignal("ClockTime"):Connect(updateCloudCover)

Any ideas why this wont work?

This won’t work because ClockTime is a whole number with a decimal.
(i.e. 14.5). Your current script does 12 * 60 + 30 which is equal to 750. Each clocktime is worth one hour. (i.e. 2.5 clock time is 2:30 AM). You would need to convert the cloudy time and clear time. 12:30 cloudy time is 12.5 clock time, so put that instead, and 15:10 is about 15.16 clock time.
Hope this helps!

So like this ?

local Lighting = game:GetService("Lighting")
local Workspace = game:GetService("Workspace")

-- Define the times of day for your changes
local cloudyTime = 12.5
local clearTime = 15.1

-- Function to update cloud cover based on time
local function updateCloudCover()
	local currentTime = Lighting.ClockTime

	if currentTime >= cloudyTime and currentTime < clearTime then
		-- It's cloudy time, set cloud cover to 0.8
		Workspace.Terrain.Clouds.Cover = 0.8
	else
		-- It's clear time, set cloud cover to 0.5
		Workspace.Terrain.Clouds.Cover = 0.5
	end
end

-- Connect the update function to run when the Lighting's ClockTime changes
Lighting:GetPropertyChangedSignal("ClockTime"):Connect(updateCloudCover)
1 Like

Did you test it? Is your script working now?

no, i made it cloudy, but there was no transition. It was just cloudy all the time.

Oh I did it with a remote event.

local Lighting = game:GetService("Lighting")
local Workspace = game:GetService("Workspace")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

-- Define the times of day for your changes
local cloudyTime = 12.5 -- 12:30
local clearTime = 15.1  -- 15:10

-- Function to update cloud cover based on time
local function updateCloudCover()
	local currentTime = Lighting.ClockTime

	if currentTime >= cloudyTime and currentTime < clearTime then
		-- It's cloudy time, set cloud cover to 0.8
		Workspace.Terrain.Clouds.Cover = 0.8
	else
		-- It's clear time, set cloud cover to 0.5
		Workspace.Terrain.Clouds.Cover = 0.5
	end
end


Lighting:GetPropertyChangedSignal("ClockTime"):Connect(updateCloudCover)

updateCloudCover()


local cloudyEvent = Instance.new("RemoteEvent")
cloudyEvent.Name = "Cloudy"
cloudyEvent.Parent = ReplicatedStorage


cloudyEvent.OnServerEvent:Connect(function(player)
	-- When the "Cloudy" event is fired, change the cloud cover
	Workspace.Terrain.Clouds.Cover = 0.8
end)

Now I need to figure out how to make it a tweened transition

Are you trying to make the clouds cloudy for everyone, or just locally?