Lights won't disable

Hello!

I recently came across a problem. Basically, I put a bunch of lights into my game which can be turned on and off. I want to disable some of the lights so that certain ones are on and some are off.

The problem is, when I join the game, the lights I selected to be disabled are still on. Does it have something to do with the on and off script?

On and off script:

local isOn = true

function on()
 isOn = true
 script.Parent.Parent.Light.PointLight.Enabled = true
 script.LightSwitchOn:Play()	
end

function off()
 isOn = false
 script.Parent.Parent.Light.PointLight.Enabled = false
 script.LightSwitchOff:Play()	
end

function onClicked()
 
 if isOn == true then off() else on() end

end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

on()

What did you do to disable the lights? In any event that last line of your script here, on(), will turn the light on by default.

I just clicked “disable” on the pointlight. How would I fix it so that if it’s disabled, it stays off?

You could set

local isOn = script.Parent.Parent.Light.PointLight.Enabled

Then remove the last line On().
This way the script will be initialized with whatever you’ve set in studio.

1 Like