Info: I am creating an experience in which players can place objects which will be saved using Datastore2, and loaded in every server. So basically permanent parts.
Issue: I can’t seem to correctly code the loading.
I have tried ListDataStoresAsync() and ListKeysAsync(), I don’t think I’m correctly utilizing them however.
My code for loading all data stores and accessing the data in each one:
local Success, PaperStore = pcall(function()
local Datastores = DatastoreService:ListDataStoresAsync()
for item, pageNo in iterPageItems(Datastores) do
print(item.DataStoreName)
local Options = Instance.new("DataStoreOptions")
Options.AllScopes = true
return DatastoreService:GetDataStore(item.DataStoreName, "", Options)
end
end)
if Success then
print("Loaded Datastores!")
local Success, Keys = pcall(function()
local Keys = {}
for DatastoreInstance, Key in iterPageItems(PaperStore:ListKeysAsync()) do
table.insert(Keys, Key)
end
return Keys
end)
if Success and Keys then
print("Loaded Keys!")
local CurrentKey = math.max(unpack(Keys))
print(CurrentKey)
local PaperData = PaperStore:GetAsync(CurrentKey)
print(PaperData)
else
warn("Error!")
end
else
warn("Error!")
end
I currently get this error:
Reminder: This is what the data looks like in Datastore Editor Plugin, I don’t know if this helps.