DataStore problem with saving multiple values

Hey! Basically, I was trying to save multiple values, to be precise, 11 values.
I’m kinda new to DataStore and how to use them.

Basically, when I leave the game, it gives me this error:

" DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key = (key) "

I don’t think 11 values are a lot, but I may be wrong.

Here’s my script!

game.Players.PlayerRemoving:Connect(function(player)
	--// Save the values in the Datastore
	
	local savedValues = {}
	
	for _, v in pairs(player.valuesFolder:GetChildren()) do
		savedValues[v.Name] = v.Value
	end
	
	local success, errormessage = pcall(function()
		backpackDS:SetAsync(player.UserId, savedValues)
	end)

	if not success then
		warn("Could not save values data! "..errormessage)
	else
		print("Values Data Saved!")
	end
		
	--// Save the owned backpacks in the Datastore
	local backpackTable = {}
	
	for _, v in pairs(player.backpackOwned:GetChildren()) do
		backpackTable[v.Name] = v.Value
	end
	
	local success, errormsg = pcall(function()
		backpackDS:SetAsync(player.UserId, backpackTable)
	end)

	if not success then
		warn("Could not save backpack data! "..errormsg)
	else
		print("Backpack Data Saved!")
	end
end)

Thanks in advance!

1 Like

This error occurs because u are saving many values to player.UserId key. Try doing this player.UserId.."-Backpack"

3 Likes

You’re running into that warning message because there’s a 6-second cooldown between writes to the same key (see limits), which also runs into another issue with your code: you’re overwriting savedValues with backpackTable. Only one value can be assigned per key in a datastore entry. In your case, you’re using the player’s ID as the key.

To fix this, I would recommend either appending a unique key to the UserId or get a unique datastore per player using the ID and then use a unique key without the ID.

3 Likes