I've been fooling around with this for a little while and I am a bit stumped. How would I create a table, insert players into that table when they join, and then insert another table inside the players tables to be able to iterate through them?
local players = {} game.Players.PlayerAdded:Connect(function(player) table.insert(players,player) end) local function GenerateInventory() local InventoryTable = { Item1 = nil, Item2 = nil, Item3 = nil } table.insert(players,InventoryTable) end local function GenerateItem() local Table = { Count = 1, Durability = 100, Cost = 50 } --Now how would I insert this into the table, replacing the first Item# that == nil with the table? end -- Should look like this local players = { InventoryTable = { Item1 = { Count = 1, Durability = 100, Cost = 50 }, Item2 = nil, Item3 = nil } } --Now lets say I need to find out how much durability the current item has. How would I iterate through these tables to find the item I am using, and how much durability it has?
Seems I misunderstood the question in my answer.
You have no way to know what player table is who, So i reccomend something like players[Player.UserId] = {TABLE}, And then to set an item value inside the table you do something like players[Player.UserId].inventory.item1 = {TABLE}
As for your last question, Yes; Likely. Unless you're storing something that says your current item is whatever slot, so it can jump to that slot for you without triyng to figure out where it is.
For the rendering purposes and what not, i'd do
for item_,item in pairs(Player.inventory) do SlotGui:GetChildren()[item_].Durability.Text = item_.durability end
Just psuedocode, but it would probably be something along those lines.