Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to receive all the data saved in a data store?

I want to get all the data (keys) stored in my datastore

This is how my data is stored:

local DSS = game:GetService("DataStoreService")
local datastore = DSS:GetDataStore("GeneralSaveData", "Players")

function saveData(player)
    local key = generateDataKey(player)
    local data = generateDataTable(player)
    datastore:SetAsync(key, data)
end

I want to get all the keys that are saved, but how would I do that?

1 comment

0

This is not possible with a global data store but you can use an ordered data store a gave the same key used in a data store.

1 answer

✓ Accepted answer

You can always store the user keys in a separate data store entry:

function saveData(player)
    local key = generateDataKey(player)
    local data = generateDataTable(player)
    datastore:SetAsync(key, data)

	datastore:UpdateAsync("__USERKEYS", function(knownKeys)
		--	Keep in mind the JSONified "knownKeys" table cannot exceed 260000 characters, so you'd want to create a new USERKEYS entry when that limit is about to be reached'
		knownKeys = knownKeys or {}
		table.insert(knownKeys, key)
		return knownKeys
	end)
end

Then you could grab them with

local knownKeys = datastore:GetAsync("__USERKEYS")

However, I cannot find a single well justified reason to do this. If you wanted to keep count of how many user data-entries there are, you should just store a single integer instead. Roblox doesn't want you to grab all the data at once because it all would need to be sent over the network and it could eat up the server's memory. (260000 characters = 2080000 bytes = 2,08 Mb, multiplied by the amount of data entries which could be up to hundreds of thousands, depending on the product)

This discussion is preserved as it was. New answers, comments, and votes are closed.