Easy Way to Grab Many of the Same Items at Once?

Hello!
I am making a hotel game and I am currently working on fixing the brightness of a mass of point lights. I will need to change a property among all of them at once, so I need to search up point light in explorer and select all of just the point lights. Is there a way I can select all of the point lights faster?
Thanks!

Screenshot:

2 Likes

You could just run a command in the command bar to change all of the point lights at once if you’re too lazy to select them 1 by 1.

for i,v in pairs( your place :GetDescendants()) do
if v:IsA("PointLight") then
--change your lights
end
end
3 Likes

So that is what that is for… (The Command Bar)
Thanks so much!
And yes, I am too lazy :laughing:

Edit: One thing: What do I need to change in that script other than…?

Just want to make sure I am not spending half an hour figuring out what I did wrong. :laughing:

Sorry for all the questions. I am just trying to get the most out of this new knowledge!
Is there a way I can do that kind of thing in game? Like a light switch for all those lights. I would need to turn all the spot lights (I made them spotlights now) to
enabled = false

Thanks!

You could just do the same code but in game. You can make a light switch with a ClickDetector or a BillBoardGui

1 Like

Put this in the command bar:

for i,v in pairs(workspace:GetDescendants()) do
if v:IsA("PointLight") then
v.Enabled = false
end
end

Explanation:

  • your place” was replaced with workspace. Workspace is where all the visible things are anyway, regardless of what place you are in.
  • for i,v in pairs(workspace:GetDescendants()) do gets all descendants of workspace - every single object in it anywhere - and loops over it. v is what the loop is currently looking at, and i is the index/number of the object it has found so far (first object? second object? 100th object?)
  • if v:IsA("PointLight") then checks whether the object currently being looked at by the loop is a PointLight. There are things in the workspace that aren’t the lights, such as parts and models. The code between this if and the end only applies if v is a PointLight.
  • v.Enabled = false changes the Enabled property. This can be changed to change it to true, or change the Name, or toggle the light (v.Enabled = not v.Enabled)
1 Like

Thanks! This is an amazing explanation and I love it!

To answer your actual question:

Easy Way to Grab Many of the Same Items at Once?]

You can use nearly the same code as above, but use the Selection service to add it to the Studio’s selection.

local addthese = {}
for i,v in pairs(workspace:GetDescendants()) do
if v:IsA("PointLight") then
table.insert(addthese, v)
end
end
game.Selection:Add(addthese)
  • local addthese = {} is an empty table.
  • table.insert(addthese, v) puts each found PointLight into the table (using it as a list)
  • game.Selection is the Selection service, which can also be gotten with game:GetService("Selection")
  • game.Selection:Add(addthese) uses its Add() method to add the found lights to the selection. Selection also has a Remove() method and a Set() method, and a Get() method that can replace the workspace:GetDescendants() in the loop.

You don’t need to use the command bar for this. In the search bar in the explorer, search for the lights. Then select the top light and scroll to the bottom, select the light at the bottom while holding shift and it’ll select all the objects between them.

2 Likes

Thank you! Is there a way I can rename them all at once?

Once they are all selected, have the properties tab open. Scroll down to name and enter the name there.