Processreceipt duplicating when buying dev product more than once

Value should be +100, everytime when bought, but it goes like, +100,+200,+300

And i also get a warning saying "DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key = "

return {
	["ProcessReceipt"] = function(receipt)
		
	end,

	[2147852555] = function(receipt)
		local player = Players:GetPlayerByUserId(receipt.PlayerId)

		
		local leaderstats = player:FindFirstChild("leaderstats")
		local moedas = leaderstats and leaderstats:FindFirstChild("Moedas")

		
		if moedas then
			moedas.Value = moedas.Value + 100
			print(player.Name .. " recebeu 100 Moedas. Total atual: " .. moedas.Value)
		else
			warn("Valor de Moedas não encontrado para o jogador: " .. player.Name)
		end

		
		return true
	end,
	}

Some other code that’s invoking that function is doing it multiple times. The code you’ve provided only increments the stat by 100. As for the warning, I’m guessing the same function that’s calling this one repeatedly is also writing receipt information repeatedly so DataStoreService notifies you it’s queueing the extra writes.

I’ve managed to fix it, and I dont think there was another code messing it (i think)

The code I posted is on a module script that Im using from a dono board that uses a process receipt aswell but can convert your needs into there so you dont need to have 2 proccess receipts

I had this one on a local script that checked the purchase (which i dont think interfered with it):

MarketplaceService.PromptProductPurchaseFinished:Connect(function(userId, productId, wasPurchased)
	if userId == Player.UserId then
		if wasPurchased then
			print(Player.Name .. " successfully purchased the product with the ID " .. productId)
		else
			print(Player.Name .. " canceled the purchase for product ID " .. productId)
		end
	end
end)

The fix (please give me feedback) (module script)

local Players = game:GetService("Players")
local MarketplaceService = game:GetService("MarketplaceService")

local productHandlers = {}

-- Define the product IDs and their corresponding handlers
productHandlers[2147852555] = function(receipt)
	local player = Players:GetPlayerByUserId(receipt.PlayerId)

	if not player then
		return Enum.ProductPurchaseDecision.NotProcessedYet  -- Retry if the player is not found
	end

	local leaderstats = player:FindFirstChild("leaderstats")
	local moedas = leaderstats and leaderstats:FindFirstChild("Moedas")

	if moedas then
		moedas.Value = moedas.Value + 100  -- Add 100 Moedas
		print(player.Name .. " recebeu 100 Moedas. Total atual: " .. moedas.Value)
	else
		warn("Valor de Moedas não encontrado para o jogador: " .. player.Name)
	end

	-- Indicate that the purchase was successful
	return Enum.ProductPurchaseDecision.PurchaseGranted  -- Indicate the purchase was granted
end

-- The main ProcessReceipt function
local function ProcessReceipt(receipt)
	local handler = productHandlers[receipt.ProductId]
	if handler then
		return handler(receipt)
	else
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end
end


return {
	ProcessReceipt = ProcessReceipt,
}


I wonder what originally caused the increasing stat. I imagine this “dono board” script does the receipt checking stuff for you, which is pretty cool! As for what you’ve provided, the handler certainly does it job fairly well. No functional issues.

I put all the product logic into a single table and made one function to manage everything, instead of creating new functions each time

It’s happened to me before, just add that line of code to the end of the function

Tried and still getting duplicated entries