Get all keys in a DataStore

Hey developers!

I’m saving tables per player of quizzes that they have created, though I also want a menu with all quizzes of all players (I think this would basically require getting all keys in the DataStore). Is there a way to do this? Any help would be appreciated!

Have a nice day!

1 Like

Correct me if I am wrong.
Store every player’s ID every time they join in a datastore. Then, when loading the datastores for all the players use :GetAsync to get the player ID you’ve saved and use it as a key to load the quiz tables they’ve created. Make sure to save the IDs in a table and use a for loop to loop through the arrays of your player table. If you are confused, let me know so I can help you more.

I know how to load a player’s quizzes, I just want a menu with all of the quizzes from all players.

1 Like

Hey, so as far as I know. You can save all the saved data into 1 specific key and then when you want to access all the data you will have to make a request to the 1 key and then you will have all data in 1 key.
Also make sure it saves the value and the player name/userid
so basically: key = “Storage” which has to be an array and each data will be a string like this: “YourValue:USERNAME:USERID”. And make sure to split the string when taking out the information. (with :split(“:”))

Hope this will help you somehow

2 Likes

Hey, thanks for your reply! I have thought about using a single table for all users, but I don’t think it’s the best solution. It’s a bit messy and just really the last thing I’ll go for…

1 Like

I agree, it’s not the best idea since the table will get larger and larger and when writing new data to the table you will have to getAsync before setting new data so a single request doesnt overwrite the whole table. I sadly I don’t have another solution but if you optimize your code good I think it wont be too bad. Also if your game gets too big single key wont handle too much data, so you gotta watch out.

2 Likes

Datastores natively support what you’re trying to do. You would probably have to implement a 3rd party workaround (hosting your own database) and creating an API to get stored data.

If you’re interested in reading more about the subject here’s a pretty in-depth tutorial. Using an external database to manage your data and more, Part 1

5 Likes

Couldn’t you use UpdateAsync? Get a DataStore that has a dictionary table and do table[playerkey] = etc. I’m assuming that if the Roblox servers get a nil return from that, the datastore won’t be overwritten.

And also, do I have to use a players UserId along with their username? Doesn’t everyone have a unique username?

Edit: I didn’t take the datastore limits into this since I’m making a feedback system where the table can only have 100-200 index size. I’m guessing I’d have to turn it into an array.

I mean sure, UpdateAsync will work I guess. haven’t thought about that, since I don’t use that.

And also, do I have to use a players UserId along with their username? Doesn’t everyone have a unique username?

^ it really depends on what information you want to collect, you can basically use either userid or the username, for punishment due to abuse of the feedback system I’d prefer to use the players UserId in the first place intead of the Name

And if you have enough feedback you can simply wipe the datastore or just use another one to not make the datastore too large

1 Like

True, but they can change it. That’s why I recommend only using the UserID, since it will always stay the same.

3 Likes