Values in Lighting cannot be changed

I’m trying to make a day/night cycle script, where once it turns night, it lowers some values in lighting to make the environment darker, and when it turns day, it raises those values back to normal.
The problem is, these values are not changing, both on server and client, as well and both on studio and normal Roblox. I have been trying to figure out why for the past 2 days and I’m at a dead end, and nobody else here seems to be having this issue, so I’m posting this now for help. Not sure if this is a bug or not, so I’m posting it in scripting help.

I have the code below, and it was originally a function inside one script but I put it inside a separate script in an attempt to see what’s wrong.

local brightness = game.Lighting.Brightness
local specular = game.Lighting.EnvironmentSpecularScale
local diffuse = game.Lighting.EnvironmentDiffuseScale
script.Parent.Audio.Music["AmbientMusic" .. math.random(1,3)]:Play()
for i = 1, 100 do
	brightness = brightness - 0.03
	specular = specular - 0.005
	diffuse = diffuse - 0.01

I tried using printing to see if the script is actually working, and yes, the script is working perfectly fine. It’s just that the values in lighting are absolutely not changing for some reason.
If anybody has a solution, i would be grateful to hear it. Thanks.

1 Like

You’re changing the variables, not the actual values under lighting.


local Lighting = game:GetService("Lighting") 
script.Parent.Audio.Music["AmbientMusic" .. math.random(1,3)]:Play()

for i = 1, 100 do
	Lighting.Brightness -= 0.03
	Lighting.EnvironmentSpecularScale -= 0.005
	Lighting.EnvironmentDiffuseScale -= 0.01

All of those things you are referencing are called Properties. You need to change the property and not just store the values and change them in a variable.

If you’re stuck on a problem, you’re most likely going at it the wrong way. Next time, instead of spending 2 days, just look at the Roblox Developer Documentation and read up on how to change properties.

Why use a for loop and not tween?

while i know how to use tweens, they are extremely complex to do compared to just using a for loop