103: Dictionary is not allowed in data stores

  1. What do you want to achieve?
    I want to make donations leaderboard.
  2. What is the issue?
    I am using the OrderedDataStore. The issue is that I need more than one value stored (The key is ID (tostring), I need to store both name and the amount of robux spent), but the Ordered Datastore does not allow me to use dictionaries in SetAsync().I’d use Global DataStore, but it does not have the GetSortedAsync() function, which is a big issue.
    The error is 103: Dictionary is not allowed in data stores.
  3. Did you look for solutions on the Developer Hub?
    I sure did. I’ve seen a situation a bit familiar to mine, though it did not help.
local function createData(plr, val)
	local playerData
	print("Creating new data for "..plr.Name)
	local success, errorMessage = pcall(function()
		playerData = db:SetAsync(tostring(plr.UserId), {
			["rbx"] = val,
			["player"] = plr
		})

	end)
	if not success then 
		warn("The attempt to create data for "..plr.Name.." was unsucsesfull: "..tostring(errorMessage))
		return 0
	end
	
	return playerData
end
5 Likes

You can’t store dictionaries in OrderedDataStores. They can only store positive integers. You should use GlobalDataStores via GetDataStore method of the DataStoreService.

4 Likes

Have you tried using JSONEncode and JSONDecode?

Edit: I just notice something else. Why are you saving the plr instance? It’s going to be nil when loading the data in another server.

1 Like

Not really, but I think I know another solution to that.
I’ll basically do few SetAsync()'s instead of putting everything into one:

   playerRobux = db:SetAsync(tostring(plr.UserId).."_robux", value)
   playerName = db:SetAsync(tostring(plr.UserId).."_name", value)

I just suddenly remembered I used the same thing in other databases, haha!
(btw, ill correct the plr instance to plr.Name thanks)

1 Like

Haha I understand your issue but I cannot help.

Using JSONEncode would probably better since you don’t have to use SetAsync for each value.

2 Likes

The error is 103: Dictionary is not allowed in data stores.

I am using the OrderedDataStore. The issue is that I need more than one value stored (The key is ID (tostring), I need to store both name and the amount of robux spent), but the Ordered Datastore does not allow me to use dictionaries in SetAsync().I’d use Global DataStore, but it does not have the GetSortedAsync() function, which is a big issue.
The error is 103: Dictionary is not allowed in data stores.

its just that I never used that before, but I’ll look into it for further work with databases, thanks! But for now, the SetAsync for each value would be fine, since I’ve got only two values to store - not much of code.

1 Like

I edited your script a bit to help you understand. You can just use HttpService:JSONDecode(JSONDictionaryHere) to make it a dictionary again when getting the data.

Edit: JSONEncode turns a table into a string, JSONDecode does the reverse.

local HttpService = game:GetService("HttpService")
local function createData(plr, val)
	local playerData
    local dataDict = {
        ["rbx"] = val,
        ["player"] = plr.Name
    }
	print("Creating new data for "..plr.Name)
	local success, errorMessage = pcall(function()
		playerData = db:SetAsync(tostring(plr.UserId), HttpService:JSONEncode(dataDict))
	end)
	if not success then 
		warn("The attempt to create data for "..plr.Name.." was unsucsesfull: "..tostring(errorMessage))
		return 0
	end
	
	return playerData
end
2 Likes

I would create an OrderedDataStore for each value.

Like this:

local CachedStores = {}
local OrderedKey = "test_key"

local function create_new_ordered_store(name)
    CachedStores[name] = OrderedDataStore:GetOrderedDataStore(name .. OrderedKey)
end

local function update_ordered_store(player, name, value)
    CachedStores[name]:SetAsync(player.UserId, value)
end
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.