Does anybody know how to make toggleable lights with only 1 switch? I tried to make a script to make headlights on my car but it only turns on and stays like that. I want it to turn on and off with only 1 button.Here is my script:
local button = script.Parent local LightA = script.Parent.Parent.PointLight local LightB = script.Parent.Parent.Parent.LightB.PointLight local LightC = script.Parent.Parent.Parent.LightC.PointLight local LightD = script.Parent.Parent.Parent.LightD.PointLight button.MouseClick:connect(function() LightA.Brightness = '10' LightB.Brightness = '10' LightC.Brightness = '10' LightD.Brightness = '10' end) button.MouseClick:connect(function() LightA.Brightness = '0' LightB.Brightness = '0' LightC.Brightness = '0' LightD.Brightness = '0'
(LightA,B,C,and D are the parts)
Heyo, Normally, to make toggle buttons you gotta do this
local button = mrbutton -- your little button local light = light -- your light local lights_are_on = false -- take a boolean value for the state of the light button.MouseClick:connect(function() -- Assuming that you have setup the Click Detector if not lights_are_on then -- check if the lights are on or not on light.Enabled = true -- if they are not on, turn them on! lights_are_on = true -- Don't forget to check out litttle boolean that helps us alot! elseif lights_are_on then light.Enabled = false-- if they are on, turn them off! lights_are_on = false -- so we know that they are off end end)
Pweh, That was easy right? now what? Well, What if someone presses it alot? omg thats just gonna trigger it soo worse that you will hate it so What do we do now?
We use Debounce! :D http://wiki.roblox.com/index.php?title=Debounce
try local table = {LightA, LightB, LightC, LightD}
button.MouseClick:connect(function() for i = 1, #table do if table[i].Enabled then table[i].Enabled = false else table[i].Enabled = true end end end)