I Wanted To Make A Light Switch With These Items: UnionOperation ("BackLamp") And The Children --> ClickDetector ("ClickSwitch") / PointLight ("Light") / A Script (Below)
local LightShine = script.Parent.Light.Enabled function onMouseClick() if LightShine == true then LightShine = false else LightShine = true --IDK How To Switch It Back To "On" :( end end script.Parent.ClickSwitch.MouseClick:connect(onMouseClick)
One of the most common problems while beginners script is setting a variable to the property. I was once the victim of this mistake... or twice.
Anyways, if you set a variable to a property, you only will return the value of the property, not the location.
local LightShine = script.Parent.Light.Enabled -- YOU: I want to set a variable to this property, because it simplifies everything. -- CODE: I want to receive the value of this property! -- YOU: *codes* print(LightShine) -- OUTPUT: -- > false -- YOU: Wait, what?
^That's how it basically goes. It will return the value of that boolean property. Same goes for any other property.
To fix this, just set the variable to the object.
local LightShine = script.Parent.Light function onMouseClick() if LightShine.Enabled == true then LightShine.Enabled = false else LightShine.Enabled = true end end script.Parent.ClickSwitch.MouseClick:connect(onMouseClick)