How to add items to a table

Hey everyone,

So I am trying my hand on a inventory system and the way I am trying to approach this is by having a folder for a player with all of the inventory contents inside the folder. For the saving part I have been trying to implement it by saving the items into a table.

Each item has the following values

What I am trying to do is to have each of the numerous inventory content to get added into the table, so something like

local function DataSaving(player)
	local tableToSave = {}
	local playerid = tostring(player.UserId)
	local playerInventory = game:GetService("ServerStorage").InventoryFolder:FindFirstChild(playerid)
	local succ, eror = pcall(function()
		for i,v in pairs(playerInventory:GetChildren()) do
			if v.ItemCode.Value == 1 then
				-- Add Item Into table

For adding the item into the table I have tried using various methods like using table.insert() or table.insert(tableToSave , table.create(1, Items Values)).

I am hoping it to look something like this

local tableToSave = {}

-- Now I try to add the value into the table, I hope it to look like

local tableToSave  = {GenericItem1 = {ItemCode = ValueProvided, ItemName = ValueProvided, ItemDamage = ValueProvided},
                      GenericItem2 = {ItemCode = ValueProvided, ItemName = ValueProvided, ItemDamage = ValueProvided}

My main question is how to add the values to the table in the form of another table, I have tried looking on the devforum but I didnt find anything that helped me out.

I have figured this out. :slight_smile:

You should write what method you decided to go with for anyone who comes across this post in the future and had the same query as you.

Will do when I have figured all the little bits of the system figured out.

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