Okay, so, your inventory system is directly just the gui then? To save in datastore2, you need to convert whatever data you want to save into a table (For clarity, strings and numbers work as well, but you really shouldn’t have single keys for those kinds of things. It would be inefficient.).
With datastore2, you can combine multiple tables under the same “key”. This is a vital part of DS2.
ds2.Combine("EXAMPLENAME", "lvl", "inventory", "money", "gamepasses", "ban")
Something like that. You combine each table you want to save. The first string you pass along is simply the name of the datastore. There is no need to change it other than for wiping players (or having multiple save files). Also multiple players can share the same name; it’s unique per player.
You may then load a single one of these tables by doing the following:
loadedstore = datastore2("lvl", player)
With this loaded store, you can hook it up to OnUpdate for it to, well, update your data whenever a request to modify this store is made.
loadedstore:OnUpdate(function(newvalue)
--say for level, you would update the level number here.
--for inventory, you would update their inventory.
end)
Now instead of adding the new item via a script, you would add it in exclusively off of that onupdate function.
--if you want to add to the past value (negative numbers work as well)
--I am unsure how it works with tables
loadedstore:Increment(value)
--or, if you want to set it directly
loadedstore:Set(value)
Once you run one of those functions, the loaded store’s respective update function would run and, well, in your case, add an item to the gui.
Finally, there is also the :Get() function. You can pass in a value and that will be the default value it will be set as if it does not find a previous value. Something like:
print(moneystore:Get(100))--prints saved money, 100 if the player had no money before
If I remember correctly, :Get() will also run the update function. However, for the first time it is called, it will not. Citation needed here, I may be wrong.
Hopefully this helps!