You just made 1 simple mistake, which I have learned from making many times myself. You used the wrong event for the ClickDetector. MouseButton1Click
is an event for GUI Objects, such as a TextButton, whereas the event you are looking for is MouseClick
.
To fix it, we'll simply swap that out with the correct event, and your code should work:
01 | local light 1 = script.Parent.Parent.L 1. SpotLight |
02 | local light 2 = script.Parent.Parent.L 2. SpotLight |
04 | function onClicked(mouse) |
05 | if light 1. Enabled = = false and light 2. Enabled = = false then |
08 | light 1. Transparency = 1 |
09 | light 2. Transparency = 1 |
11 | elseif light 1. Enabled = = true and light 2. Enabled = = true then |
12 | light 1. Enabled = false |
13 | light 2. Enabled = false |
14 | light 1. Transparency = 0 |
15 | light 2. Transparency = 0 |
20 | script.Parent.ClickDetector.MouseClick:connect(onClicked) |
And now this should work!
If you have any further problems/questions, please leave a comment below and I'll see what I can do. Hope I helped :P
Also, as Cheeky pointed out above, it would be simpler to just use an elseif instead of using two different if statements. It's more convenient, and allows the code to run smoother.