Should I use UpdateAsync or SetAsync?

So I’m trying to make an equip system and when I set async a table value of an inventory it gave me the message: “DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key = Player_185041318.” This is the line and it’s not a repeating line because when I printed a message it only printed once.

game.ReplicatedStorage.Events.EquipUnit.OnServerEvent:Connect(function(p, units)
	game.ReplicatedStorage.Events.EquipUnit:FireClient(p, units)
	table.clear(inven) -- inven is the inventory table
	for i,v in pairs(units) do
		table.insert(inven, v)
	inv:SetAsync("Player_" .. p.UserId, inven) -- I printed a message and it only printed once

If updateAsync is the answer, then how should I use it?

Use :SetAsync when the player has no data and use :UpdateAsync() when the player has data.
In the function you put, the player data is nil or not.

    return Value

UpdateAsync has certain benefits over SetAsync, but you have to actually use them. Code that does not leverage the old data might as well be using SetAsync. There are threads explaining how to use UpdateAsync separately, such as the one below, but overall use SetAsync for quick and dirty saving and UpdateAsync for careful operations taking previous data into account.

Never use UpdateAsync and have the transformFunction look like this:

whatever:UpdateAsync(whatever2, function(old)
	return {data = something new}

If you aren’t using old, don’t use UpdateAsync.

Edit: UpdateAsync won’t help your issue here, though. The problem is that you’re saving too frequently. Try saving at set intervals (e.g. once a minute) or when a player leaves instead of every time the event fires.


That’s not really how it works. UpdateAsync will first of all, queue everything. UpdateAsync should be used for saving data, in this case, comparing data. It will give you the old data for you to mess with and see what’s inside, then you can use that for saving tecnics. You shouldn’t test things just to use : SetAsync (), UpdateAsync is a Get/Set combo.

is there a way to send 2 data store requests at the same time? or should there be a delay

I think the cooldown is six seconds, do I have to wait 6 seconds before another request?

Yes, you have to wait between requests. You can find more info about datastore limits here:

Like my other post said, the solution is to not save as much.

1 Like

how should I do it inside studio, I don’t think it will fire playerremoving in studio? Also, is it possible if I set like 7 datastores (each 6 seconds apart) after the player is removed?

You only can as long as it’s not the same key.

If you set a BindToClose function with a delay it will fire PlayerRemoving in studio. You can also test in a test server and have the player leave before the server disconnects.

1 Like

You should be trying to save data using Tables, and have as much data in one key as possible if you’re not doing that;

(“Services” like DS2, ProfileService make that easy)

If you need to use more than 4MB of data inside a datastore, you might wanna look into compressing the data.

Would doing something like: (“Player_” … (player.UserId + 1), value), (“Player_” … (player.UserId + 2), value), etc work?

No, look at the tables page to understand tables.

Tables allow you to save multiple data in one basically.

Also you should NOT modify the userId “indicator”, what if skmeoke has that userId? Data would collide.

It depends on what data you put.
If it is a simple one like boolean, number or short string it will take less than a minute. If it is a large table or a very long string it could take longer.