Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

1 answer

✓ Accepted answer

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.

1 comment

0

:O you are the only reason i know remote events <3

This discussion is preserved as it was. New answers, comments, and votes are closed.