Is there any way to shorten this light switch without creating a variable?

if Object.LightObject.PointLight.Brightness == 0 then
	Object.LightObject.PointLight.Brightness = 1
else
	Object.LightObject.PointLight.Brightness = 0
end

Reason I don’t want to create a variable is because I’m not worried about organization and cleanliness. I just feel like there’s a much more efficient way to do this.

1 Like
local PointLight = Object.LightObject.PointLight

PointLight.Brightness = math.abs(PointLight.Brightness - 1)

if the brightness is 0 it will turn into 1 and vice versa

EDIT: I messed up the variable, fixed now

1 Like

Thanks!

I’m about to shorten a lot of if statements. :slight_smile:

Out of curiosity: why does the Enabled property not work for you? Setting the Brightness to 0 is essentially the same as disabling the light unless you have a use case that requires it to be on while it’s not actually emitting any light?

You should be able to just set the Enabled property to the inverse of its current setting.

Object.LightObject.PointLight.Enabled = not Object.LightObject.PointLight.Enabled
1 Like

Edit: I made a better explanation.

Since Brightness = 0 and Enabled = false are the same and my script is about tweening (didn’t mention this, oops), I decided to kill two birds with one stone. Enabled = false wouldn’t have worked anyways just because of how my client and server effects modules handle things.