No error but it isnt working, ~~~~~~~~~~~~~~~~~ on = true local bulb1 = game.Workspace.Light_Model.Light.PointLight.Enabled
function onClick() if bulb1 == true then on = false elseif bulb1 == false then on = true end end
script.Parent.ClickDetector.MouseClick:connect(onClick) ~~~~~~~~~~~~~~~~~
Well, I think the problem is that you're expecting something to happen. If you just change the value of on when the button is clicked, then you won't notice a change. The only thing that will change is the value of open.
Try changing your script to this, this will make the light on or off.
on = true local bulb1 = game.Workspace.Light_Model.Light.PointLight.Enabled function onClick() if on == true then on = false bulb1 = false elseif on == false then on = true bulb1 = true else print("An error has occurred with the light script.") end end script.Parent.MouseClick:connect(onClick) --also, you don't connect to the ClickDetector, you connect to the part that has the ClickDetector in it.
In the future, make sure your code is in a code block. It's that little blue dot that says 'Lua' in it, like this:
on = true local bulb1 = game.Workspace.Light_Model.Light.PointLight.Enabled function onClick() if bulb1 == true then on = false elseif bulb1 == false then on = true end end script.Parent.ClickDetector.MouseClick:connect(onClick)
I will assume that you want to turn the light on and off when clicked. This is simple to do, and just takes a little rearranging of your code.
local on = true local bulb1 = game.Workspace.Light_Model.Light.PointLight
Using local variables for each makes it easier to read and less laggy. Also notice that I set bulb1 to the pointlight, not the pointlight's Enabled property. This is because when you set a variable to an instance's property, the variable becomes whatever the property is at the time the variable was defined. It will not change if the property changes, and you can not change the property by changing the variable.
if on == true then on = false bulb1.Enabled = false elseif on == false then on = true bulb1.Enabled = false end
Read this a few times, I hope it makes sense, because I'm not sure how to explain it further. If on is true, we turn the light off. If on is false, we turn the light on. Simple.
Hope I helped!