How to get ordered datastore from dictionary?

im trying to do this to get levels sorted

local playerData = game:GetService("DataStoreService"):GetOrderedDataStore("userDataStore") 
local http = game:GetService("HttpService")

while true do
	local pages = playerData:GetSortedAsync(false, 30)
	local topThirty = pages:GetCurrentPage()
	for rank, data in ipairs(topThirty) do
		local plrId = data.key
		local data = http:JSONDecode(data.value)
		local level = data
		print(rank, data)
	end
	
	task.wait(300)
end

but my data is saved in this format:

	local data = {
		["Points"] = points,
		["Level"] = level,
		["XP"] = xp
	}
	
	repeat
		if tries < 5 then
			success, errorMessage = pcall(function()
				return userDataStore:SetAsync(plrID, http:JSONEncode(data))
			end)
			tries += 1

anyway to do it without having save everything in separate datastores?
thanks

Note, you cant, Ordered datastore only support positive int though you could use the table as a ground truth and the save another data store for level

1 Like