A way to select parts with command bar?

Let’s say I wanted to change the color of the trees but I already have duplicated it around the map.

I don’t want to go through replacing everything so is there a way I can select all of the trees without searching it up in the explorer?

Perhaps through the command bar?

Keep in mind, I’m not a scripter so go easy on me.

This is just something I wanted to know in case I’ll encounter another problem similar to this.

3 Likes

Command Bar? I don’t believe you can, that can only accept 1 line of code

However you can do this via a script using GetDescendants() I believe:

local Trees = workspace.Kingdom.Detail.Trees["Oak Trees"]:GetDescendants()
local ColorToChange = BrickColor.new("Shredded Potato") --This is just an example, change this to whatever you want lol

for _, Leaves in pairs(Trees) do
    if Leaves:IsA("BasePart") then
        Leaves.BrickColor = BrickToChange
    end
end
2 Likes

Actually you can use multiple lines of code in the command bar, it just condenses it into a line when pasting into it, but if you copy back the line and paste it, it’ll keep the formatting I believe

2 Likes

Well if you want to select the parts, which I’m assuming that you do, there’s a nice example on how to use Selection (service)

In your case I would throw this in the command bar

local Selection = game:GetService("Selection")
 
local newSelection = {}
for _, object in pairs(workspace:GetDescendants()) do
	if object.Name == "Leaves" then
		table.insert(newSelection, object)
	end
end
 
Selection:Set(newSelection)
4 Likes

Paste this script I made into the command bar. Set the name variable to the name of the things you want to select.

local objects = {}

local lookForName = "Baseplate" -- Name of things you want to select.

for i,v in pairs(workspace:GetDescendants()) do
	pcall(function()
		if v.Name == lookForName or lookForName == "all" then
			table.insert(objects,v)
		end
	end)
end

game:GetService("Selection"):Add(objects)
3 Likes

Thanks for all the replies! Each script looks different :0, I’ll definitely check them out.

And yes I do want to select the parts in case I want to change something else besides color.

1 Like

Oh ok

image

local Trees = workspace.Kingdom.Detail.Trees["Oak Trees"]:GetDescendants()
local ColorToChange = BrickColor.new("Neon orange") 

for _, Leaves in pairs(Trees) do
    if Leaves:IsA("BasePart") then
        Leaves.BrickColor = ColorToChange
    end
end
3 Likes

Hi, seeing as how others have given the code to solve this issue I just want to recommend this paid plugin that might make doing stuff like this a little easier: InCommand by Elttob & boatbomber. For whatever reason I didn’t like using the regular command line in Studio and found this plugin very useful. It’s helped me work with large groups of models all at once and do things similar to what you’re doing here. I like it because it keeps the formatting in your scritps and it can also save your scripts. I’m also not super into Roblox scripting yet but I found faster and easier to practice with this plugin. It is not free, however.

You can read more about this plugin in this post. Keep in mind that this plugin isn’t necessary, but you may want to consider it. If you decide to use this plugin I hope it helps!

1 Like

Do this inside of the command bar

for _, selected in pairs(Location:GetChildren()) do --[[Do what you want here, remove the brackets and the --. selected is all the selected parts.]] end

It works but it also changes the trunk’s color.

1 Like

Confused, where do I specify what to select?

Thanks! Both of these worked!

What if I wanted to make it more specific though? I have 2 different types of trees in-game, one is Oak and the other is Pine.

Of course, the scripts made me select every leaf but I want it to be just Oak’s leaves.

Anyway to do that?

Excuse me if I’m being too inquisitive.

1 Like

I mean assuming that their parent’s name is oak, you can do a check like this

if object.Parent.Name == "Oak" then

Modified code

local Selection = game:GetService("Selection")
 
local partName = "Leaves"
local parentName = "Oak"

local newSelection = {}
for _, object in pairs(workspace:GetDescendants()) do
	if object.Name == partName and object.Parent.Name == parentName then
		table.insert(newSelection, object)
	end
end
 
Selection:Set(newSelection)
6 Likes

After the do.

for _, selected in pairs(game.Workspace:GetChildren()) do selected:Destroy() end
2 Likes