What's the best way to handle a bunch of datastore requests?

Best way of handling sword equipment from database in one main script (maybe more if needed for the solution)

Greetings, fellow community developers! I’ve hit an issue with my sword fighting game, where I’ll have to properly give all players their equipped swords at the same time. This is relying on a default datastore table for each indiviual, looking like this:

		PlayerInv = {
			["Swords"] = {"Sword1"}; -- could be multiple swords
			["Equipped_Sword"] = {"Sword1"}; -- will always be one sword
			["Boosts"] = {}
		}

I’m thinking of using pcall(function() with DataBase:GetAsync to all players in the server using a for loop, however this might be bad and will probably - by my knowledge - end up causing too many requests at once.

All of the actual sword equipment will happen in a serverscript, which is why I’ll probably have to use a method with a for loop. There cannot be much wait() time, as this can cause the round selection to slow down and eventually run everything at inconsistent speeds.


Any code can help solving this problem. Thanks in regards.- Dev_Mathe

To simplify, “what’s the best way to handle a bunch of datastore requests?”

To clarify, you should not care much about the requirements given in this case, as I’ll just modify the script according to the answer.

You can make some sort of function that caches the inventory when it gets updated instead of updating it straight away in the data store. Then you can have some sort of service to evenly distribute the data store calls you need to make in the background that saves the cache to it.

This way you can make sure your not requesting too much at once when getting your inventory since it would be from a cache and requires no actual calls and therefore will not yield.

All of this can be done in the background if you use DataStore2 or even ProfileService
I would personally recommend DataStore2, however developing your own service/system is still viable.