Processing Receipt keeps queuing DataStore requests

Hello!

I was recently using the (pain giving) Process Receipt (function?!?!) and I encountered a small error.

Essentially, when someone purchases a dev product, I want two functions to run as well as to add a certain amount to an IntValue. This all goes well until the saveData() function.

Code:

market.ProcessReceipt = function(receiptInfo)
	local plrId = receiptInfo.PlayerId
	local plr = players:GetPlayerByUserId(plrId)
	local pID = receiptInfo.ProductId
	
	if receiptInfo.ProductId == 1190464049 then
		plr.ValueFolder.XP.Value = plr.ValueFolder.XP.Value + 10000
		sendPurchaseConfirm(plr, pID, "10 000")
		saveData(plr)
	end
	
	if receiptInfo.ProductId == 1190463498 then
		plr.ValueFolder.XP.Value = plr.ValueFolder.XP.Value + 1000
		sendPurchaseConfirm(plr, pID, "1 000")
		saveData(plr)
	end
	return Enum.ProductPurchaseDecision.PurchaseGranted
end

Errors are:

  • ReceiptId (the id) already being processed.
    ^This error appears the third time when purchasing a dev product
  • DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key = 448151576 - XP (x2)
    ^This error appears the second time when purchasing a dev product

I only receive a Discord notification for all 3 purchases on the sendPurchaseConfirm() function, I do not receive any Discord notification for any of the 3 purchases I did with the saveData() function.

here is the saveData() function:

local function saveData(playerWhoBought1)
    local success , errorMessage = pcall(function()
        valDs:SetAsync(playerWhoBought1.UserId.." - XP", playerWhoBought1.ValueFolder.XP.Value)
    end)
    
    if errorMessage then
        return
    end
    
    if success then
        local data = {
            ["embeds"] = {{
                ["title"] = "A Player's Data Has Not Been Saved After Purchasing a Dev Product",
                ["description"] = playerWhoBought1.Name.." data did not save after purchasing a dev product",
                ["color"] = 16711680,
                
                ["fields"] = {
                    {
                        ["name"] = "Player Name",
                        ["value"] = playerWhoBought1.Name,
                    },
                    {
                        ["name"] = "Player ID",
                        ["value"] = playerWhoBought1.UserId,
                    },
                    {
                        ["name"] = "Last Recorded Value",
                        ["value"] = "XP: "..playerWhoBought1.ValueFolder.XP.Value,
                    },
                    {
                        ["name"] = "error message",
                        ["value"] = errorMessage
                    }
                }
            }}
        }
        local finalData = http:JSONEncode(data)
        http:PostAsync(url2, finalData)
    end
end

the reason why this isn’t working is 100% bc of the saveData function since once removed I do not receive the errors anymore.

The XP also seems to add up every time, so after buying 1000 XP, if I buy 1000 XP again, 2000 XP is rewarded to me (in one single purchase).

Thanks!

You can’t set/get a datastore more than 5 seconds (I THINK: per key). This is fixable with a simple wait.

2nd:

  • ReceiptId (the id) already being processed.
    ^This error appears the third time when purchasing a dev product

Can you show the error or copy paste the full error. Because I haven’t seen this error before.

error:
ReceiptId f63a8877535e797b17fe94777902871a already being processed.

So, a DataStore can only get set or be fetched once every 5 seconds per player?!?