Please read the guidelines of the Scripting Support category in the future before posting. Scripting Support is not a venue to ask for free code. Your request for advice, however, is valid.
There are many different numbers of ways to do this.
Typically you want to first get your structure down for this kind of a system. Ask yourself; are you looking for something primitive, or something complicated? Can each beam or light be a quick flip, or does it need to have special effects per type of effect?
If you’re looking for a primitive flicker, you can look up the CollectionService which allows you to utilise an assortment of API to group objects by a tag. Since each light-based effect has the Enabled property, you can set it straight away as well. Remember to add your tags manually in Studio.
If you’re interested in keeping track of tags, I’d recommend the Tag Editor plugin created by Tiffblocks.
-- Borrowing Operatik's code but this is better ;)
local CollectionService = game:GetService("CollectionService")
local LightsEnabled = true -- or false?
-- If you need to assign at runtime. Replace "container" with a model path. Workspace works too.
for n, descendant in pairs(container:GetChildren()) do
if descendant:IsA("Beam") or descendant:IsA("Light") then
CollectionService:AddTag(descendant, "LightObject")
end
end
-- Enable function (does not handle BaseParts! write that yourself!!!)
local function ConfigureLights()
LightsEnabled = not LightsEnabled
for n, tagged in pairs(CollectionServicd:GetTagged("LightObject")) do
tagged.Enabled = true
end
end
This is obviously not complete code and it’s not in a style I’d like it in, though it gives you an example of how you’d structure such code. If I wrote the code for myself, it’d have a few more handlers included regarding handling initial and different states, not just a one-off function.
There are many other ways to achieve this desired functionality, including:
- ModuleScripts
- Folder-based hierarchies
- Getting children or descendants of containers
- CollectionService (above)
Look around the Developer Hub for potential items that might help you. It’d be great to know basic things, such as generic for loops, to help you achieve what you need.
I have not linked any articles because I am on mobile with low battery and it would help to search those up, in case you stumble across anything else of good use. I’m also lazy, it’s 3:55 AM.