Need Help With Table Sorting

Hi everyone!

Recently I’ve been trying to make a case clicker game and I am having issues when wanting to group similar items (In the same table) into different seperate tables. For example I check for data on the client in a folder called “Owned Items” which contains all the items the player owns, but I want to group the same items into seperate tables, so that in the players inventory I can do like x3 of this item. I don’t really know a way to go at this, but I have tried to make different folders with values of how many items their are, but that did not work and it was hard to code.

1 Like

There’s probably two approaches to this, you could either have multiple values of the same type in the table something like this:

local example = {
   ["sameThing1"] = value,
   ["sameThing2"] = value
}

Or you could store a property that tells you how much of each value your player has:

local example = {
   ["thing1"] = {
      ["value"] = …,
      ["amount"] = 1
   },
   ["thing2"] = {
      ["value"] = …,
      ["amount"] = 2
   }
}

(too lazy to capitalize everything sorry lol)




you can then loop thru the table to sort em like this:

local example = …

for i, v in example do
   local amount = v.amount
   --[[ other code
   like you can clone that value
   x amount of times
   depending on what v.amount is
   ]]
end
1 Like

Oh ok so when I add the data to the players profile I would just increase amount +1 and then get that amount. Let me try that and see if it works

1 Like