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

I’m kind of new to data stores and UpdateAsync, so if anyone knows the problem, please tell me!

local DataStoreService = game:GetService("DataStoreService")
local myDataStore = DataStoreService:GetDataStore("myDataStore")-- :GetDataStore means you're getting a data store that has been saved in the game.

-----------------Loading Data------------------
game.Players.PlayerAdded:Connect(function(player)
	
	--Data

	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local Cash = Instance.new("IntValue")
	Cash.Name = "Cash"
	Cash.Parent = leaderstats
	
	local Rebirths = Instance.new("IntValue")
	Rebirths.Name = "Rebirths"
	Rebirths.Parent = leaderstats
	
	
	
	--Codes
	local codeStats = Instance.new("Folder")
	codeStats.Name = "CodeStats"
	codeStats.Parent = player
	
	local codes = require(game:GetService("ReplicatedStorage").Modules.Codes)
	for i, Code in ipairs(codes) do
		local bool = Instance.new("BoolValue")
		bool.Name = Code
		bool.Parent = codeStats
	end
	
	
	
	
	
	
	local playerUserId = "Player_"..player.UserId


	--Load Data

	local data
	local success, errormessage = pcall(function()
		data = myDataStore:GetAsync(playerUserId)
	end)

	if success then
		if data then
			
			Cash.Value = data.Cash
			Rebirths.Value = data.Rebirths
			
			--Codes
			local codes = require(game:GetService("ReplicatedStorage").Modules.Codes)
			for i, code in ipairs(player.CodeStats:GetChildren()) do
				for dataValue, v in pairs(data) do
					if dataValue == code.Name then
						code.Value = dataValue
					end
				end
			end
			
		end
	end

end)



-----------------------Saving Data-------------------------
game.Players.PlayerRemoving:Connect(function(player)
	local playerUserId = "Player_"..player.UserId
	
	
	local data = {
		Cash = player.leaderstats.Cash.Value;
		Rebirths = player.leaderstats.Rebirths.Value;		
	}
	
	for i, v in ipairs(player.CodeStats:GetChildren()) do
		data[v.Name] = v.Value
	end

	
	
	local success, errormessage = pcall(function()
		myDataStore:UpdateAsync(playerUserId, function(oldData)--This is the part I changed from GetAsync to UpdateAsync.
			return data
		end)
	end)
	
end)

1 Like

Use SaveAsync (or SetAsync, I forgot what the method is called), not UpdateAsync.

1 Like

I keep seeing posts about how you should use UpdateAsync instead of SetAsync

1 Like

I don’t see a use for UpdateAsync. For data saving, I use Datastore2 which is a module you can find online, I think you should try it too.

1 Like

UpdateAsync() is generally a lot slower and more resource intensive than SetAsync() because it reads the value and also updates it, versus only setting it to a new value. I would also add a timer on the function so you don’t overload the server and lose data.

1 Like

Should I use this? Link

I think you should use SetAsync() in a pcall function or the Datastore2 module, however you can go whatever way you want with it. The post you linked is technically right about the data loss prevention, but if you wrap it in a pcall the errors are significanty less common.

1 Like

Most developers make the mistake of going with faster over safer which can result in data loss. I highly suggest using Update instead of Set so the player doesn’t lose their data.

even if they are less common Data loss in a game is one of the top ways that a player will quit playing the game. Always go the safer route even if it is harder or longer to get working. This way you won’t lose valuable players due to Roblox’s stupid bug-filled engine.

1 Like

If a player joined for the first time, would I use updateasync or setasync? Because how would I update something that doesn’t exist yet?

1 Like

I asked a question a while ago, and I’m still wondering about it. I’m not sure if you saw it, but I’ll quote it right here.

If a player joined for the first time, would I use updateasync or setasync? Because how would I update something that doesn’t exist yet?