To give some context, this script changes the color of an alarm light on the click of a button on a Surface GUI. I recognize that it is inefficient but how can I fix it?
parent = script.Parent alarms = game.Workspace.Alarms light1 = light1.SpotLight light2 = light2.SpotLight glass1 = glass1 glass2 = glass2 SecurityStationFrontAlarm = alarms.SecurityRoomFrontAlarm SecurityStationLeftALarm = alarms.SecurityRoomLeftAlarm SecurityStationRightALarm = alarms.SecurityRoomLeftAlarm script.parent.GreenButton.MouseButton1Down:connect(function() --GREEN PRESSED SecurityStationFrontAlarm.glass1.BrickColor = BrickColor.new("White") SecurityStationFrontAlarm.glass2.BrickColor = BrickColor.new("White") SecurityStationFrontAlarm.light1.Range = 0 SecurityStationFrontAlarm.light2.Range = 0 SecurityStationFrontAlarm.light1.Color = Color3.new(0, 0, 0) SecurityStationFrontAlarm.light2.Color = Color3.new(0, 0, 0) end) script.parent.YellowButton.MouseButton1Down:connect(function() --YELLOW PRESSED SecurityStationFrontAlarm.glass1.BrickColor = BrickColor.new("Bright Yellow") SecurityStationFrontAlarm.glass2.BrickColor = BrickColor.new("Bright Yellow") SecurityStationFrontAlarm.light1.Range = 40 SecurityStationFrontAlarm.light2.Range = 40 SecurityStationFrontAlarm.light1.Color = Color3.new(255, 255, 0) SecurityStationFrontAlarm.light2.Color = Color3.new(255, 255, 0) end) script.parent.RedButton.MouseButton1Down:connect(function() --RED PRESSED SecurityStationFrontAlarm.glass1.BrickColor = BrickColor.new("Bright Red") SecurityStationFrontAlarm.glass2.BrickColor = BrickColor.new("Bright Red") SecurityStationFrontAlarm.light1.Range = 40 SecurityStationFrontAlarm.light2.Range = 40 SecurityStationFrontAlarm.light1.Color = Color3.new(255, 0, 0) SecurityStationFrontAlarm.light2.Color = Color3.new(255, 0, 0) end)
Remember to identify the locations of the items, such as in lines 5-6 they need to have the location of where the brick is
parent = script.Parent alarms = game.workspace.Alarms light1 = light1.SpotLight light2 = light2.SpotLight glass1 = "LOCATION OF THE GLASS1" glass2 = "LOCATION OF THE GLASS2" SecurityStationFrontAlarm = alarms.SecurityRoomFrontAlarm SecurityStationLeftALarm = alarms.SecurityRoomLeftAlarm SecurityStationRightALarm = alarms.SecurityRoomLeftAlarm script.parent.GreenButton.MouseButton1Down:connect(function() --GREEN PRESSED SecurityStationFrontAlarm.glass1.BrickColor = BrickColor.new("White") SecurityStationFrontAlarm.glass2.BrickColor = BrickColor.new("White") SecurityStationFrontAlarm.light1.Range = 0 SecurityStationFrontAlarm.light2.Range = 0 SecurityStationFrontAlarm.light1.Color = Color3.new(0, 0, 0) SecurityStationFrontAlarm.light2.Color = Color3.new(0, 0, 0) end) script.parent.YellowButton.MouseButton1Down:connect(function() --YELLOW PRESSED SecurityStationFrontAlarm.glass1.BrickColor = BrickColor.new("Bright Yellow") SecurityStationFrontAlarm.glass2.BrickColor = BrickColor.new("Bright Yellow") SecurityStationFrontAlarm.light1.Range = 40 SecurityStationFrontAlarm.light2.Range = 40 SecurityStationFrontAlarm.light1.Color = Color3.new(255, 255, 0) SecurityStationFrontAlarm.light2.Color = Color3.new(255, 255, 0) end) script.parent.RedButton.MouseButton1Down:connect(function() --RED PRESSED SecurityStationFrontAlarm.glass1.BrickColor = BrickColor.new("Bright Red") SecurityStationFrontAlarm.glass2.BrickColor = BrickColor.new("Bright Red") SecurityStationFrontAlarm.light1.Range = 40 SecurityStationFrontAlarm.light2.Range = 40 SecurityStationFrontAlarm.light1.Color = Color3.new(255, 0, 0) SecurityStationFrontAlarm.light2.Color = Color3.new(255, 0, 0) end)