So what do I want to achieve? I want to learn how to use datastores for more than just simple values. I’m specifically talking about a way to store inventory values, similar to games like sols rng, dungeon quest, mm2. Anything with an inventory system seems so confusing to make and when trying to look thing up, it seems really difficult to scale.
So what exactly am I trying to get from this post? I’m trying to look for a good tutorial or resource to help me learn how to use datastores. I have looked at tutorials but they’ve only ever seemed to explain what I already know, a very limiting method of how to store data or not explain what is happening well enough for me to understand why I should be doing it/how to do it.
hi! a lot of inventory systems use tables to store their data. this can be saved as a string by using JsonEncode() when saving and JsonDecode() when loading.
local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")
local dataStore = DataStoreService:GetDataStore("PlayerInventoryData")
Players.PlayerAdded:Connect(function(Player)
local setSuccess, setResult = pcall(function()
return dataStore:SetAsync(tostring(Player.UserId), {["Food"] = 5, ["Water"] = 10})
end)
if setSuccess and setResult then
local getSuccess, getResult = pcall(function()
return dataStore:GetAsync(tostring(Player.UserId))
end)
if getSuccess and getResult then
print(getResult)
end
end
end)
Some quickly put together server script, it seems to print the table just fine.
How is something like an item in fisch or grow a garden stored? There is custom properties like weight as well as size, is it like the name of the base item and its properties in a list inside of a list of all the items someone owns? And then when it loads in it takes the base model from a dictionary type thing and then scaled according to size property, colored to color property or is it just saved as like a model inside of the datastore?