What's the best way to datastore the player's purchases?

Hi! :smiley:
So, what’s the best way to save a player’s purchases in a datastore? For example, if I have a sword shop, with a lot of swords. You don’t have to buy them in a specific order. What would be the most data-efficient way to store which items a player has?
I was thinking an array of numbers (like 1110110111), but I am still not sure about how would I go about this problem.
P.S I’m not asking for the entire data store system, I know how to store data, I am asking about the most efficient form to store the data in.
Thanks in advance,
Sorry if I was being unclear,
Mun :smile:

3 Likes

I would do an array of booleans if I wanted to reduce the cost as much as I can. So it would look like that for example:

local player1Data = {
    Swords = {
        true, -- has sword 1
        false, -- doesn't have sword 2
        true, -- and so on...
        true
    }
}

And yes, if you allow the player to buy sword 1 for example three times, then I would make integers instead of booleans in my array.

1 Like

However I suggest to store some information not only about if the player has the item but also some information identifying the item he has, because in the future if you decide to remove one of the swords completely from the game you will have an useless entry in the array (can be solved by using that entry for a new item), that’s why in my game I assign an ID to every item and store it like that (it’s more complex in my game but I will give a simple example):

local player1Data = {
    Items = {
        [1] = 1,
        [2] = 0,
        [3] = 5,
        [4] = 1,
        [10] = 1
    }
}

And now if you remove item 3 from the game, you simply remove Items[3] from the array, but in our original solution, you would have to keep the third element of the array because removing it would mess up the system by changing the indexes of the further elements.

Also this solution is more clear and easier to modify.

2 Likes

And one more thing, in my second solution, you don’t need to store information about items that have count of 0. You simply store data only about items the player has, so that reduces the cost because instead of that:

local player1Data = {
    Items = {
        [1] = 1,
        [2] = 0,
        [3] = 5,
        [4] = 0,
        [10] = 1
    }
}

You will have

local player1Data = {
    Items = {
        [1] = 1,
        [3] = 5,
        [10] = 1
    }
}
4 Likes