So I’ve realized I need to use an OrderDataStore but for some reason I cant store dictionaries into them, it works with a normal datastore but with an Ordered one it doesnt.
So that sucks fr fr so is there a way around this?
Apparently if I make a datastore called “topics” and from the look of it using :GetOrderedDatastore(‘topics’) it gives me a deferent datastore basically. If I save something to the datastore it wont be in the orederedDatastore so now I cant use the stuff, so I tried saving data to just the orderedDatastore and you know what happened(Mention above).
So what can I do about this if I cant save dictionaries and what not? Im so confused
I have never used OrderedDataStores so I’m not sure if this will work, but maybe convert the dictionary to JSON before saving it.
Ok yeah I think I’ve heard of that before, how can I convert it to one and then when I get the data convert it back?
You just have to use HttpService:JSONEncode and HttpService:JSONDecode
local HttpService = game:GetService("HttpService")
local Data
local success, errormessage = pcall(function()
Data = YourDataStore:GetAsync(Key)
end)
if success then
DecodedData = HttpService:JSONDecode(Data)
end
--Saving
local DataToSave = HttpService:JSONEncode(YourData)
local success, errormessage = pcall(function()
YourDataStore:SetAsync(Key, DataToSave)
end)
After doing this it now says “DataStoreService: ValueNotAllowed: string is not allowed in data stores. API: SetAsync, Data Store: Topics”.
At this point what can I even store 
I just checked the documentation and it says that ordered data stores can only be positive integers.
Hmm well do you know how I can fix this? I dunno what Im doing
What exactly are you trying to do with the datastore?
Im trying to save a dictionary to it that contains stuff like strings and numbers, I then also want to be able to at one point loop through them like using :GetSortedAsync() that way I can loop through them and get X amount of the asyncs or whatever they are called
I just looked at the documentation again and it seems like your best option is to save those strings as the keys. When you are loading the data, you can just go through the first few pages. I probably can’t help you much from here since I have never used ordered data stores before.
Here is the example the documentation listed:
local DataStoreService = game:GetService("DataStoreService")
local pointsStore = DataStoreService:GetOrderedDataStore("Points")
local function printTopTenPlayers()
local isAscending = false
local pageSize = 10
local pages = pointsStore:GetSortedAsync(isAscending, pageSize)
local topTen = pages:GetCurrentPage()
-- The data in 'topTen' is stored with the index being the index on the page
-- For each item, 'data.key' is the key in the OrderedDataStore and 'data.value' is the value
for rank, data in ipairs(topTen) do
local name = data.key
local points = data.value
print(name .. " is ranked #" .. rank .. " with " .. points .. "points")
end
-- Potentially load the next page...
--pages:AdvanceToNextPageAsync()
end
-- Create some data
pointsStore:SetAsync("Alex", 55)
pointsStore:SetAsync("Charley", 32)
pointsStore:SetAsync("Sydney", 68)
-- Display the top ten players
printTopTenPlayers()
1 Like
So turns out that roblox only supports numbers in the value, so I’ve found a workaround, ill just create a script the turns a string to a number and then a number to a string
1 Like