How to use :GetDescendants() to return array with object paths?

I’m trying to figure out how to use :GetDescendants() to return an array with all objects with certain name’s paths, such as: If the parts are named “TestPart” then it returns with all paths of all bricks named “TestPart”

local testtable = {}
local testdescendants = workspace:GetDescendants()
for i,v in pairs(testdescendants) do
	-- I'm stuck at this part	
end

are you talking about something like this?

local testtable = {}
local testdescendants = workspace:GetDescendants()
for i,v in pairs(testdescendants) do
	if v.Name == "TestPart" then
        print(v.Name.." Found")
    end
end
1 Like

I’m trying to get it to get the path, so for example the result would be: workspace.Model.TestPart

Can’t you just call :GetFullName on every part that is named “TestName” by using an conditional check?

local testtable = {}
local testdescendants = workspace:GetDescendants()
local testnameinstancepaths = {}

for i,v in pairs(testdescendants) do
	if v.Name == "TestPart" then
        table.insert(testnameinstancepaths, v:GetFullName()) 
        --Alternatively, you could just do what you want to with them here, instead of storing them in a table to do something else with it later.
    end
end

--Do what you want to do with testnameinstancepaths table here.
1 Like