Getting the Path within a Table

--[[
    Hello, another Topic with just a code block in it. So right now, I am 
    wondering if it is possible to get the Path of an Object like how you can 
    with Instance:GetFullName()? If so, How will I do this?
    
    Thanks :3
--]]



























-- what?
1 Like

A little bit trickier than with Instance:GetFullName(), shall I say.

local dictionary = {Name = "Dealership"}
dictionary.SuperClass = {Parent = dictionary, Name = "Car"}
dictionary.SuperClass.ChildClass = {Parent = dictionary.SuperClass, Name = "Seats"}

function ExportFullName(dictionary:table, Separator:string)
local lastParent = dictionary
local str = ""
while lastParent do
str = lastParent.Name..Separator
lastParent = lastParent.Parent
end
return str
end

print(ExportFullName(dictionary.SuperClass.ChildClass, "/")) --> Dealership/Car/Seats

I’m not confident this code will work, but it’s a general concept if your system is using OOP. It’s probably similar to what Roblox uses for GetFullName.

What this does is it loops through the parent until it is not found anymore.

1 Like