I have a script for a button, so that once pressed it sounds an alarm and changes the lighting around the map. The script runs perfectly, but the repeated code to change all the separate lights seems a little ridiculous, so I am hoping there is a way to avoid it? I have around 50 lights total (so this script is merely a snippet), all of which located in the exact same place, "game.Workspace.FacilityLighting".
function onClicked()
local Alarm = script.Parent.BreachAlarm
if Alarm.Playing == true then
Alarm.Playing = false
game.Workspace.FacilityLighting.Light1.SurfaceLight.Color = Color3.new(255/255, 0/255, 0/255)
game.Workspace.FacilityLighting.Light2.SurfaceLight.Color = Color3.new(255/255, 0/255, 0/255)
game.Workspace.FacilityLighting.Light3.SurfaceLight.Color = Color3.new(255/255, 0/255, 0/255)
game.Workspace.FacilityLighting.Light4.SurfaceLight.Color = Color3.new(255/255, 0/255, 0/255)
else
Alarm.Playing = true
end
end
script.Parent.ClickDetector.MouseClick:Connect(onClicked)

3 comments
think u mean for _, light in pairs(facilityLighting:GetChildren()) on line 12?
Expected identifier, got ')', appears on the closing bracket beside the final end.
Code fixed. Sorry :p