I want to make a light switch for a room in my friend’s place.
The script I am using (tried to make my own) is not working.
Here's the script I am using
local lights = true
local ClickDetector = script.Parent.ClickDetector
local ne = Enum.Material.Neon
local gl = Enum.Material.Glass
function onMouseClick()
if lights == true then
lights = true
script.Parent.Parent.Parent.LightA.LptA.SpotLight.Enabled = true
script.Parent.Parent.Parent.LightA.Neon1.Material = ne
script.Parent.Parent.Parent.LightA.Neon2.Material = ne
script.Parent.Parent.Parent.LightB.LptB.SpotLight.Enabled = true
script.Parent.Parent.Parent.LightB.Neon3.Material = ne
script.Parent.Parent.Parent.LightB.Neon4.Material = ne
else
lights = false
script.Parent.Parent.Parent.LightA.LptA.SpotLight.Enabled = false
script.Parent.Parent.Parent.LightA.Neon1.Material = gl
script.Parent.Parent.Parent.LightA.Neon2.Material = gl
script.Parent.Parent.Parent.LightB.LptB.SpotLight.Enabled = false
script.Parent.Parent.Parent.LightB.Neon3.Material = gl
script.Parent.Parent.Parent.LightB.Neon4.Material = gl
end
end
ClickDetector.MouseClick:connect(onMouseClick)
I guess “local lights = true” works as a switch, in the statment “if lights == true then” you are not switching the “lights” to false, you are making it true again. change the bool value in the line 8 to “lights = false” and in the line 16 to “lights = true”.
Here is your script fixed:
local lights = true
local ClickDetector = script.Parent.ClickDetector
local ne = Enum.Material.Neon
local gl = Enum.Material.Glass
function onMouseClick()
if lights == false then ---> I change this value
lights = true
script.Parent.Parent.Parent.LightA.LptA.SpotLight.Enabled = true
script.Parent.Parent.Parent.LightA.Neon1.Material = ne
script.Parent.Parent.Parent.LightA.Neon2.Material = ne
script.Parent.Parent.Parent.LightB.LptB.SpotLight.Enabled = true
script.Parent.Parent.Parent.LightB.Neon3.Material = ne
script.Parent.Parent.Parent.LightB.Neon4.Material = ne
elseif lights == true then ---> I change this value
lights = false
script.Parent.Parent.Parent.LightA.LptA.SpotLight.Enabled = false
script.Parent.Parent.Parent.LightA.Neon1.Material = gl
script.Parent.Parent.Parent.LightA.Neon2.Material = gl
script.Parent.Parent.Parent.LightB.LptB.SpotLight.Enabled = false
script.Parent.Parent.Parent.LightB.Neon3.Material = gl
script.Parent.Parent.Parent.LightB.Neon4.Material = gl
end
end
ClickDetector.MouseClick:connect(onMouseClick)