How to insert a table inside a table?

I did a research but I still don’t understand why it is returning nil.


on line 27 I inserted another table into a table but it’s saying it’s nil.
When I print it , I actually get both table
image
image
image

3 Likes

Use {} to show you’re making a table.

Inventory is an instance, not a table. You can’t put tables in it, but you can keep a configuration and values inside it if that’s what you meant.

Would I do this? image

image It didn’t get inserted to the table. Also, inventory is a table. image

give me a more detailed report of what you’re trying to do, I might be able to help. I am just not good at understanding things when several pieces are given

To insert a table using table.insert do:

table.insert(Table.TableIndex, {StuffHere})
1 Like

Ok, so what I’m tryna do is, I’m tryna insert a table of this

,
(just the specific one for example “Cannon”).
Here is the inventory table inside the player -
image

and here is the script -

The bindable finds item type[Towers] then rarity[Basic] then finally, the item. which is the final table I want to put into the player’s inventory.

My problem here is, I don’t know how.
Now what I did in final was that, but it kinda broke it.
image

inventory is a variable, adding data to it will be useless if not saved, you need to “set” the data too

Yes, I didn’t show it, but I was using datastore2
image

is userDataStoreName and dataKey the same?

Yes. Other things does save, I’m not worried about the datasaving because it does work, I’m just tryna insert a table here.

are you sure it saves or is it showing up a default table? saving on a different key changes a lot
I am not able to see one of these variables but they shoul be the same for the saving and loading to have the same key

as in this data adding function, you’re using the dataKey as key at loading and userDataStoreName as key at saving

Yea it is the same. Datasaving does work once again. The key is just inside a module.
I’m just tryna insert a table inside a table here buddy.

try to print variable inventory before and after, I want to see the table so I can research it a bit more.

(so after making the inventory variable and after setting the data after the if statement)

I have to loop through it. You can’t print a table.

afbeelding
you can print a table since quite recently

You want me to print this image
variable? The :Set() function is basically just like setasync. It will not affect the value.

I know, print userdata at getting and at settings -w-

I did image
image