Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

DataStore - get all keys to go in a for loop?

Asked by
iFlusters 355 Moderation Voter
7 years ago

So I have a basic datastore:

local dataStore = game:GetService("DataStoreService"):GetDataStore("Example")

How can I get all the keys to do this:

for i, v in pairs(dataStore) do
    print("Key: " ..v)
end

I don't have any of the key names, so I can't do GetAsync().

0
I guess the first thought that popped into my mind would be to save all the keys with a "Skeleton Key", thing. Then you could loop through, using all the keys saved to the main key, and get the information from those keys. I would like to see if there are better methods to do this, though. Good question. OldPalHappy 1477 — 7y
0
Yeah, although there will be a string limit at one point. iFlusters 355 — 7y

1 answer

Log in to vote
0
Answered by
cabbler 1942 Moderation Voter
7 years ago

Unless you make the datastore as one key with one value which is a table, you can't loop through a datastore. It is meant to get data for specific players. If you are only concerned with data for players in the current server, you should make a simple table called "localDataStore" or something. When the player joins, store their data in that table. Then you can loop through data.

Ad

Answer this question