This video is a demonstration/explanation onhow to toggle an array of lights from ON to OFF. If you enjoyed the video consider giving it a thumbs up! If you have any questions do not hesitate to leave a comment. :)
Socials:
Twitter: / nebuladigest
Discord Channel: / discord
(Un-copylocked) Place File: https://www.roblox.com/games/97874833...
CODE:
-- if you haven't already, watch the video to better grasp the concept!
-- © 2022 | Nebula274
local folder = workspace:FindFirstChild("Lights")
local lights = folder:GetChildren()
local button = script.Parent.Parent
local state = true -- true when on, false when off.
local timeToWait = .1
local function updateState()
if state == true then
state = false
button.BrickColor = BrickColor.Green()
for i = 1, #lights do wait(timeToWait)
local light = lights[i]
local visual = light:FindFirstChild("SpotLight")
visual.Enabled = false
light.Material = "Plastic"
end
elseif state == false then
for i = 1, #lights do wait(timeToWait)
local light = lights[i]
local visual = light:FindFirstChild("SpotLight")
visual.Enabled = true
light.Material = "Neon"
end
state = true
button.BrickColor = BrickColor.Red()
end
end
script.Parent.MouseClick:Connect(updateState)