How do dictionaries work in DataStore2?

I’ve been having a hard time understanding how to use DataStore2 with dictionaries. I’ve stumbled some forum posts that have useful information but then sometimes that information just confuse me more. Are there any articles about this topic or any information I should know? Thanks!

Dictionaries are no different from strings in that both are JSONEncoded when saving to Roblox’s DataStores, which is what DataStore2 allows you to do.

local store = DataStore2("String", playerObject)
store:Set(
    {
        k = 10,
        c = "str",
    }
)

-- save just like
store:Set("meta")
1 Like

This article will really help you out,

1 Like

Actually my table is kind of like a dictionary within a dictionary like this:

local function setupPlrData()
    local plrDataTable = { -- get data from database through IDs
	    ["itemInventory"] = {}, -- MaxSlot = 18
		["defenseInventory"] = {
			["hat"] = {
				["ID"] = nil},
			["torso"] = {
				["ID"] = nil},
			["leggings"] = {
				["ID"] = nil},
			["sword"] = {
				["ID"] = nil}
		    },
		["currencyValue"] = {
			["Aurum"] = 0,
			["Crystallo"] = 0,
			["XP"] = 0
		}
    }
	return plrDataTable
end

so I get errors really often:(

This has actually been my basis for my code but then there was no mention on how to connect the dictionary to keys so I’ve been kinda lost and wondering if my code is working or just a mess.

I was messing around with the code earlier then I found out what was wrong. I was trying to set the player’s data when they joined with :Get() rather than :Set() and then I was trying to get that table with dataStore(name, plr) rather than dataStore(name,plr):Get() then not setting the data after changing the value which gave me a lot of errors. Thank you for the help though! I learned a lot through this!

1 Like