Lighting Changes when Clock Time has changed

I need to change the look of lighting when the clock time has changed to a certain time.

But the issue is however, from the code I have made so far it doesn’t seem to work, and doesn’t put out an output issue. What I am looking for is if this is working code, how to loop the code or where to place it in the explorer.

I have also attempted to find other ways to loop the code, such as while true do, but this doesn’t seem to work in my case.

The clock time changes in another script, which is functional, but this script doesn’t return any errors, or change the lighting at all.

local Lighting = game.Lighting
local Time = Lighting.ClockTime

while true do
	wait(1)
	if Time > 18.3 or Time < 6 then
		Lighting.EnvironmentDiffuseScale = 0.202
		Lighting.EnvironmentSpecularScale = 0.202
		Lighting.ColorCorrection.Enabled = true
	elseif Time < 18.4 or Time > 6 then
		Lighting.EnvironmentDiffuseScale = 1
		Lighting.EnvironmentSpecularScale = 1
		Lighting.ColorCorrection.Enabled = false
	end
end

Are there any errors?


local Lighting = game.Lighting
local Time = Lighting.ClockTime


 game.Lighting.Changed:Connect(function()
      if Time > 18.3 or Time < 6 then
		Lighting.EnvironmentDiffuseScale = 0.202
		Lighting.EnvironmentSpecularScale = 0.202
		Lighting.ColorCorrection.Enabled = true
	elseif Time < 18.4 or Time > 6 then
		Lighting.EnvironmentDiffuseScale = 1
		Lighting.EnvironmentSpecularScale = 1
		Lighting.ColorCorrection.Enabled = false
	end
end)

This only works with a day and night cycle script inserted into the game.

No, no errors as said in the message.

Do I paste this into the day and night cycle script? Or where should I put the script for the lighting, as this isn’t changing the lighting. It also came back with the error
" ServerScriptService.LightingChange:4: attempt to index number with ‘Changed’ "

Is the time changing script client or server sided?

The time changing script is server sided.

You’re not updating your Time variable.

Code:

local Lighting = game:GetService("Lighting")

while task.wait(1) do
	local Time = Lighting.ClockTime

	if Time > 18.3 or Time < 6 then
		Lighting.EnvironmentDiffuseScale = 0.202
		Lighting.EnvironmentSpecularScale = 0.202
		Lighting.ColorCorrection.Enabled = true
	elseif Time < 18.4 or Time > 6 then
		Lighting.EnvironmentDiffuseScale = 1
		Lighting.EnvironmentSpecularScale = 1
		Lighting.ColorCorrection.Enabled = false
	end
end
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.