How do I make a on/off button for a point light or a spot light?
Here you go:
on = false script.Parent.ClickDetector.MouseClick:connect(function(click) if on == false then on = true script.Parent.PointLight.Enabled = true else on = false script.Parent.PointLight.Enabled = false end end)
So here is how you should order your parts:
1.Create the switch/brick. 2.Put the PointLight/SpotLight in it. 3.Put a ClickDetector in the brick as well.
-Thank me by accepting this answer/bumping up my reputation!
w = workspace.whatever if w.Transparency == 0 then w.Transparency == 1 elseif w.Transparency == 1 then w.Transparency == 0 end end
I did it similar to Shawnyg, but I used the range value instead. So you can choose how bright it is via code.
local onoff = 2 --- onoff = 2 then light is on --- onoff = 1 then light is off function onClicked(playerWhoClicked) if onoff == 1 then script.Parent.SpotLight.Range = 10 onoff = 2 else script.Parent.SpotLight.Range = 0 onoff = 1 end end script.Parent.ClickDetector.MouseClick:connect(onClicked)
If onoff equals 2 at the start, the light is already on prior to the game starting. If onoff equals 1 at the start, the light is off prior to the game starting.
That code also assumes that the Script, ClickDetector and SpotLight is in the same brick.
This code also applies to a PointLight, you just have to change the word SpotLight to PointLight.
ok so ibasically im very smol
You can always reuse someones old light switch and create your own with that tool. If you want to start from scratch I suggest making the model before you add scripting.
But it's mainly just scripting. I never had time to go around creating the first ROBLOX light bulb, luckily other people did that for us.