How would i select only one type of part (Ex:Union) Using the command bar?

The title says it all I need to select only unions using the command bar.

Ive looked on youtube but i cant find anything and i have no idea how to select things using a script.

--assume this is going through a model with all the different parts on roblox
for _, part in pairs(model:GetChildren()) do
    if part:IsA("Union") then
        print("its a union")
    end
end

Documentation:
https://developer.roblox.com/en-us/api-reference/function/Instance/IsA

1 Like

But that doesnt select the union i already know how to make a for loop to loop through the entire workspace to delete all unions (Thats the reason im asking this is to clean up lag) but i need to know how to selecting what im trying to do is select all the unions and convert them into a mesh.

local union = workspace:FindFirstChildOfClass("UnionOperation")

“FindFirstChild”/“FindFirstChildOfClass”/“FindFirstChildWhichIsA” will all fetch the first instance which matches the argument passed to the function.

1 Like

what?

1 Like

To clear some confusion i want to SELECT the unions like this

then what do you want to do

1 Like

Select the union? It has the blue box around it meaning its selected thats what i want to do but for all the unions without going through all of them.

I mean what do you want to do with the unions after you select them all

local Selection = game:GetService("Selection")
local selected = Selection:Get()
for _, part in pairs(model:GetChildren()) do
    if part:IsA("Union") then
        table.insert(selected, part)
    end
end
Selection:Set(selected)
2 Likes

Comes up with this error

local Selection = game:GetService("Selection")
local unions = {}
for _, part in pairs(model:GetChildren()) do
if part:IsA("Union") then
    table.insert(unions, part)
end
end
Selection:Set(unions):3: attempt to index nil with 'GetChildren'
local Selection = game:GetService("Selection")
local selected = Selection:Get()
for _, part in pairs(workspace:GetChildren()) do
    if part:IsA("Union") then
        table.insert(selected, part)
    end
end
Selection:Set(selected)
1 Like

Nvm that was the error from the other script but it still wont work?

I fixed it! You just needed to change the “Union” to “UnionOperation”.