Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Returning a tree of all the parents a object is inside?

Asked by 5 years ago

https://gyazo.com/38924ad7bb90346602087c6252965b01

For example here, what would I use to print the entire directory of objects that the textbutton "left" is inside of?

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

In short, if you're only interested in displaying the path of some object then you can use obj:GetFullName(). This returns a string of the object's hierarchy. For example:

local p = Instance.new("Part")
p.Parent = workspace

print(p:GetFullName()) --> "Workspace.Part"

If you want a more useful result, say for example, a table of ancestors, you'd have to write this function yourself. I assume ROBLOX will add this feature some time in the near future, though.

local function GetAncestors(obj)
    local parent = obj.Parent
    local ans = {}

    while (parent) do
        ans[#ans+1] = parent
        parent = parent.Parent
    end

    return ans
end

Let me know if you have any questions. hope this helps.

0
:O you are the only reason i know remote events <3 Fad99 286 — 5y
Ad

Answer this question