Best way to save dictionary's to a ordered datastore?

I’m trying to make a datastore which will be used to store dictionary’s for player information. I then hit a road block where datastores cant save dictionary’s. I cant use tables since I need to set specific information to these values. Is there a way I can some how format to have it be stored and easily have access to? Thanks in advanced! <3

Code that does not work

local data = {
	SoundId = "6542800230", --// Sound Id
	UploaderUserId = "1031904", --// User Id
	UploadDate = "6/9/2021" --// Upload Date
}
MusicODS:SetAsync("Alex", data)

Datastores can store dictionaries, is there an error you are experiencing?

Edit: as clarified by @Kaid3n22 you have to use a normal datastore

use a global datastore for this, not an ordered datastore. ODS’ can only store integers. normal/global ones can store dictionaries, arrays, and integers. something like this:

local DS = game:GetService("DataStoreService")
local MusicDs = DS:GetDataStore("Music")
1 Like

That won’t work you need a big code with playerAdded , playerRemoved, :BindToClose() and more stuff with key which is the plr UserId

My bad changed the title, I am using ordered datastores so I can access through plenty of servers.

Can you clarify what you mean by access through plenty of servers?

Im trying to make GUI that will replicate for everyone then just in the server you are in. Which is going to be cloned from the “datastore”

So a sort of global gui system?

I guess you can say that, Im a bit new to datastores so I only know normal datastores and ordered if you know what I should be using I can look into it.

I believe you should be using a normal datastore, also MessagingService might be useful for sending a message to all servers to update their gui

With normal datastores am I still able to loop through all the users as with ordered datastores?

Unfortunately you can’t, so what you could do instead is have an ordered data store with all of the keys of the normal data store and you can retrieve the information by looping over the ordered data store, then getting the data from the key provided

This is similar to the berezza data saving method that is used in datastore2

1 Like

Can you provide me a example code (Just a tiny bit) of what is being done?

Unfortunately I am on my mobile device currently and I won’t be on a device with a keyboard until 7 or so hours have passed, so I guess you would have to wait unless someone else posts some code.

ok that’s fine, thanks for the help!

I’m sorry for not replying, I just completely forgot about this.

Code is a bit messy

local DataStoreService = game:GetService("DataStoreService")
local keys = DataStoreService:GetOrderedDataStore("keys")
local store = DataStoreService:GetDataStore("store")

local function SetData(key, value)
    local success, err = pcall(function()
        keys:SetAsync(key, os.time())
        store:SetAsync(key, value)
    end)
end

local function GetKeys()
    -- You can add your own page collection code
    local pages = keys:GetSortedAsync(false, 10)
    local currentPage = pages:GetCurrentPage()
    return currentPage
end

-- To access everything you could do this
local function GetRecentData()
    local keyTable = GetKeys()
    local data = {}
    for dataKey, _ in pairs(keyTable) do
        local success, err = pcall(function()
            local storedData = store:GetAsync(dataKey)
            data[dataKey] = storedData
        end)
    end
    return storedData
end
2 Likes