What do you want to achieve?
I want to make donations leaderboard.
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.
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
You can’t store dictionaries in OrderedDataStores. They can only store positive integers. You should use GlobalDataStores via GetDataStore method of the DataStoreService.
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.
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
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