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
end
end
end)
end
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.