You can work with a table, but you’ll have to run a for loop.
local Lights = {
script.Parent.Light1,
script.Parent.Light2
}
for _, light in next, Lights do
print(light)
end
-- or
for _, light in pairs(Lights) do
print(light)
end
Put all your lights into a folder, then put all the objects into a table.
local lights = {} -- list of our lights
for i,light in pairs(LightsFolder:GetChildren()) do -- run through all the children of the lights folder, add them to our list
table.insert(lights, light) -- add the light
end
-- now the "lights" table will consist of all the lights that were in the folder
Since you’re looking to easily manage groups of instances, the CollectionService would work perfectly for you! This service allows you to manage groups of instances by setting tags on individual instances.
Using the AddTag method, you can add a tag to an instance like so: game:GetService('CollectionService'):AddTag(instanceToSetTagFor, tagName)
Using the GetTagged method, you can get a table of objects with the tag like so: game:GetService('CollectionService'):GetTagged(tagName)
@Sweetheartichoke has made a very nice plugin to visually manage tags in Studio. This would make it very easy to add the “Lights” tag to all your light instances in Studio.
Once you set the tags for the lights, you can easily go through the entire table to enable/disable them.
local Lights = game:GetService('CollectionService'):GetTagged('Lights')
for _, light in pairs(Lights) do
light Toggle.Value = not light.Toggle.Value
end
Now these are all mixed answers but to be straight to the point, you can simply use :GetChildren() on a folder/model/anything parenting the objects with all the lights in them. To toggle them just loop through and enable or disable them that way.
This is probably the easiest and simplest way to do this, and should hopefully suit your needs.