"Searching" through dataStores

I want to have a system were users can create there own pixel hats, faces, ect. However, I want users to be able to search these hats by there name (name filtering is already in place)

Is there a way for me to “search” data stores for a string?

I can format it in pretty much any way, if that helps. (Values that need to be stored: key value (integer), name of item (string), data for item (table))

Iterating through all the dataStore pages will not be a good option later on when there are many more creations.

Any help would be appreciated, Thanks.


I believe that you should have a table of the hats/items that the user owns when retrieving data from the DataStores and instantly loading all of the hats to a frame on the user. When the user searches for a hat, just make a number of them invisible and shift the hats on the frame around. Not sure on how many total has there would be though so this may not be the best solution.

1 Like

There is no way to iterate through a DataStore in the way that you’re suggesting.

DataStorePages is an object reserved for OrderedDataStores in which you can flip through pages by a specified sort. This is not going to work for the use case you have in mind.

The only way you’re getting such a system is by storing your items in a value assigned to a single key and that’s bound to overflow once you start adding items. So essentially, that’s a no-go.

Unless you have some wizard powers prepared to acknowledge the limitations of DataStores and store pages of inventories by key with values being full data (which is far too complicated and bound to throttle), this system can’t happen.

1 Like

Personally if I were you I would create my own web server with a custom database with custom methods used for searching the database. However I’m not you. And also I don’t necessarily have a place to put that much data if it got very populated.

So to answer your question without using an external database, it is not possible to search through a data store.

That being said here’s a theoretical way to search through a data store:

Instead of storing data for each player, store each value as a table including the UserId of the person who created it and then the data all under a singular key. From there you can implement search methods based on the data within it. (If you want to show the player someone else’s stuff then you can also store the same data on a separate key for the player.)

Data could be structured like this:

["Owner"] = Player.UserId,
["Title"] = "Title",
["Data"] = {"I assume you have a system here for the data"}
  • Will let you create your search feature
  • Can do it all within Roblox
  • Might overload if used too popularly
  • Very fragile (if data gets corrupted you’re entire thing is out until a new key is made)

So if I were using this method, I would do this:
Personally I would use os.date() and get the current day as a key. This way you could have players search through the newest items. Then if you want you could have players look through different days. It’s very tacky and not very smooth but it is an idea.

In summary, there is no way to search through a data store. The best option would probably be to host your own database but that has a lot of problems on its own.

1 Like

Roblox data stores definitely aren’t well suited for this task. Any solution would be incredibly hacky or expensive, at best.

The easiest possible solution I can think of is to just prefetch all the hats ahead of time when a server starts, and then lookup through those (this will most definitely fail if you have too many hats, however).

You could always “abuse” data store keys a little, and store every prefix of a string as a new key. For example, if I wanted to store the hat “Dominus Somethingus”, I would store it in the prefix “D”, the prefix “Do”, the prefix “Dom”, and so on. This will most definitely get really expensive and might be slow though, so use it with caution. Also you might have collisions of prefixes here, which would need something like a table of possible hats with the same prefix for each key.

If you are set on doing this on Roblox datastores, I would recommend some combination of the two - use the server as a cache for the datastore, and cache queries every time they are made (along with “nearby” results).