Why do I have so many queues?

Whenever I try to save a table, it always says that I am requesting too many queues. I am a little confused on this and would like to know what I am doing wrong here if you can help. I am still currently trying to learn how to save tables, so there is not much I can do on my own. Currently I have made a game called Bacon Escape, which is still in alpha, so I am trying to make some changes to my datastore that way there isn’t data loss, but I can’t seem to find a way.

Here is the script
local ds = game:GetService("DataStoreService"):GetDataStore("SkinsBaconEscape1.0")

game.Players.PlayerAdded:Connect(function(player)
	local key = "skins-"..player.UserId
	
	local folder = Instance.new("Folder", player)
	folder.Name = "Access"
	local save = ds:GetAsync(key)
	if save then
		for i = 1,#save do
			print(save[i].." skin loaded")
			local temp = Instance.new("BoolValue", folder)
			temp.Name = save[i]
		end
	end
end)

game.Players.PlayerRemoving:Connect(function(player)
	local key = "skins-"..player.UserId
	
	local AccessSaved = {}
	for i,v in pairs(player.Access:GetChildren()) do
		table.insert(AccessSaved, v.Name)
		ds:SetAsync(key, AccessSaved)
		print(v.Name.." has saved")
	end
end)

All help is apreciated! :slightly_smiling_face:

1 Like

I would recommend leveraging a library such as DataStore2 or Quenty’s datastore system.

You should be good, if the player has no new data, checking the old database to see if there is data there, and if there is, moving it over to the new system.

These libraries manage making sure the datastores are used responsibly and ratelimits are rarely (or never) hit.

I can’t see anything wrong with your script, but using a library like one of those will almost always make it easier down the road to do your shtuffs.

It looks like your constantly setting the the key with SetAsync to something different.


Edit: Let me elaborate.
This line:

for i,v in pairs(player.Access:GetChildren()) do
	table.insert(AccessSaved, v.Name)
	ds:SetAsync(key, AccessSaved)
	print(v.Name.." has saved")
end

Your getting all items, and saving to that 1 specific key. So, your firing it repeatedly.
Edit 2: Fixed formatting
Edit 3: So the solution is just to wait(6) so it doesn’t fire the limit.

1 Like

Oh, I see the issue.

Move this:

	ds:SetAsync(key, AccessSaved)
	print(v.Name.." has saved")

to after the loop, so your complete code is now:

local ds = game:GetService("DataStoreService"):GetDataStore("SkinsBaconEscape1.0")

game.Players.PlayerAdded:Connect(function(player)
	local key = "skins-"..player.UserId
	
	local folder = Instance.new("Folder", player)
	folder.Name = "Access"
	local save = ds:GetAsync(key)
	if save then
		for i = 1,#save do
			print(save[i].." skin loaded")
			local temp = Instance.new("BoolValue", folder)
			temp.Name = save[i]
		end
	end
end)

game.Players.PlayerRemoving:Connect(function(player)
	local key = "skins-"..player.UserId
	
	local AccessSaved = {}
	for i,v in pairs(player.Access:GetChildren()) do
		table.insert(AccessSaved, v.Name)
	end

	ds:SetAsync(key, AccessSaved)
	print(v.Name.." has saved")
end)
2 Likes

Also be sure to wrap SetAsync and GetAsync inside pcalls or they might error and stop your script.

wow how did I not see that, lol. See sometimes people like me just make simple mistakes. Thanks, if you can I would love to learn how to leverage a library like you said up top, especially if my game ever gets popular like piggy.

@GravityAccel thanks for that extra note.