How to learn how to use datastores for more than just basic numbers?

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.

Any support would be appreciated! :smile:

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.

Pretty sure Roblox already handles tables without JsonEncode and JsonDecode? Correct me if I am wrong.

no, if you try to store any type of table, you will get an error

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.

Not sure where you heard this from. My game has been saving tables to datastores for over 5 years.

It’s the Roblox engine data types that you can’t store. If you try saving a table that contains a Roblox engine data type, then that will error.

I can vouch, this is the case.

Also roblox automatically does the json methods if I recall correctly, so you dont have to worry about it.

I heard this from my console, when I attempted to do it.

I would like to see your code that did that because it must have had some incompatible type in there.

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?