Is there any ready function to get the current instance PLUS all descendants?

I have a tree of parts where the parent is also a part:


If I want to change the properties of the entire tree, I have to repeat the same instructions for the parent and all descendants:

local function ChangeProp(item)
    item.Transparency = 1
    item.Color3 = Color3.fromRGB(85, 170, 0)
end

ChangeProp(part)
for _, item in pairs(part:GetDescendants()) do
    ChangeProp(item)
end

Are there any GetDescendants commands that include the Parent together?

There isn’t a way to include the parent like that. Your best bet is to just edit the parent’s properties, then loop through the descendants afterwards:

local function ChangeProp(item)
    item.Transparency = 1
    item.Color3 = Color3.fromRGB(85, 170, 0)
end

ChangeProp(part)
for _, Item in pairs(part:GetDescendants()) do
    ChangeProp(item)
end

So you want Instance:GetDescendants() that includes the parent? If so then the most you can do is write a function to do it for you

local function get_descendants_include_parent(parent)
    local t = parent:GetDescendants()
    table.insert(t, 1, parent)
    return t
end
3 Likes

Objective and elegant solution (as always) … thanks!

1 Like