How can i create desedants in tables with a script

if you didnt understand, my apology i probably made this unclear, but anyways
i want with a script to do this

(i made an image to show how its like)

image

“Name” being the parent
and then the “Things” are the children of that parent so when i access it with a script it becomes like this

Name.Thing

so how can i make this using a script?

Not sure exactly if this is what you want but I’ve added another item so you see how to modify it as well. One thing to be careful of is also using a variable like Name. All Roblox objects have a property called Name which has priority so I typically make my key and object names like PlayerName or something longer.

local Name = {
	["Thing"] = "Thing",
	["Thing2"] = "Thing",
	["Thing3"] = "Thing",
}

Name["Thing4"] = "NewThing"

print(Name)
print(Name.Thing)

you could do

local Table = {
[“Name”] = {
[“Thing”] = {Object = (path)}}
}

or if u mean to add to a table Table.insert(table, value)

I was facing a similar issue earlier today and this is how I overcame the problem:

Table["Name"]["DescendantName"] = "Value"

This can add a descendant to the table or set the value of a descendant that is currently in the table.

1 Like

appreciated very much, for some reason there was no answer anywhere.

local grandparentTable = {
    name = "Grandparent",
    age = 60,
    hobbies = {"Reading", "Gardening"}
}

local parentTable = setmetatable({
    name = "Parent",
    job = "Engineer",
    children = 2
}, {__index = grandparentTable})

local childTable = setmetatable({
    name = "Child",
    grade = 10,
    hobbies = {"Sports", "Drawing"}
}, {__index = parentTable})

local grandchildTable = setmetatable({
    name = "Grandchild",
    grade = 5,
    hobbies = {"Video Games", "Cycling"}
}, {__index = childTable})

print(grandchildTable.name)        -- Output: Grandchild
print(grandchildTable.age)         -- Output: 60
print(grandchildTable.job)         -- Output: Engineer
print(grandchildTable.hobbies[1])  -- Output: Video Games
1 Like

A bit hard core but why not learn deep.

1 Like

thank you for the help!

stupid character limit

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.