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

How to browse Data Store? (or put keys into table)

How can I browse Data Store. For example, I have a Data Store:

key0 value0 key1 value1 key2 value2

Can I somehow put all keys in Data Store to the table to edit it with scripts?

1 answer

Yes, but you will need a separate request for each key.

local ds = --[[initialize datastore here]]
local t = {}
local keys = {"key0", "key1", "key2"}
local numOut = #keys
local errorOccurred = false
for i = 1, #keys do
	coroutine.resume(coroutine.create(function()
		local key = keys[i]
		local success, value = pcall(function() t[key] = ds:GetAsync(key) end)
		numOut = numOut - 1
		if not success then errorOccurred = value end
	end))
end
while numOut > 0 do wait() end
if errorOccurred then
	warn("Error occurred. Message: " .. errorOccurred)
	--Deal with the error here
else
	--Can use 't' at this point
end

Notably, you cannot browse a datastore's keys unless you're using an OrderedDataStore (which has the limitation of integer values only); you have to know what keys you're using in advance.

2 comments

0

This is not what I want. It writes keys like key1, key2, key3. That was an example. In mine DS keys named differently.

0

Edited to be more general

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