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)
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")
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.
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
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.
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