Product purchases keep stacking

  • within my code, i have the following lines on the end of a major script:

[SCRIPT]

playerEvents.Purchase.OnServerEvent:Connect(function(player, productId, productName)
	if configurationsModule["Shop"][productName]["GamepassId"]~=nil then
		marketplaceService:PromptGamePassPurchase(player, configurationsModule["Shop"][productName]["GamepassId"])
	else
		marketplaceService:PromptProductPurchase(player, productId)
	end
end)
-- this small section decides does it give gamepass purchase or a product purchase based on does it find gamepassId within a configurationsModule

local function processReceipt(receiptInfo)
	print("PURCHASE")
	local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
	local productId = receiptInfo.ProductId
	local productName = marketplaceService:GetProductInfo(productId, Enum.InfoType.Product).Name
	print(player.Name.." bought "..productName.."("..productId..")")
       -- some further logic
end

local function processGamepass(player, gamepassId, hasPurchased)
	local productName = configurationsModule["GamepassIds"][tostring(gamepassId)]
	print(player.Name.." bought "..productName.."("..gamepassId..")")
	player.Gamepasses:FindFirstChild("Gamepass_"..productName).Value=1
end
marketplaceService.ProcessReceipt = processReceipt
marketplaceService.PromptGamePassPurchaseFinished:Connect(processGamepass)

[SCRIPT]

  • i will note, all of this is not within any kind of loop, and is not in a script that can duplicate and play multiple times, however there is an issue where when i buy something once everything is good, but when i buy it again then the logics play out twice, next time its 3, then 4 etc.

  • i have just added (some further logic) as that is not the important part, it has no loops and plays out only once.

  • this is what output had (without some other printing that is unrelated):

  • first purchase:
    PURCHASE - Server - CoreScript:639
    borotoni73 bought placeholder_name(3610664069) - Server - CoreScript:644

  • second purchase:
    PURCHASE (x2) - Server - CoreScript:639
    borotoni73 bought placeholder_name(3610664069) (2) - Server - CoreScript:644

  • does anyone know how can fix this issue, as when i went to check i was buying too fast and i waited like 5 minutes between the purchases it still played out the logics and prints twice

1 Like

The issue is that you are not returning Enum.ProductPurchaseDecision.PurchaseGranted in the processReceipt function, which causes Roblox to think that something went wrong with granting the purchase and subsequently retries the processing (causing the stacking you observed).

The solution is fairly simple, with only one line needing to be added at the end of your processReceipt function:

return Enum.ProductPurchaseDecision.PurchaseGranted

I recommend having a look through the documentation for ProcessReceipt, as it has a bit more information.

1 Like

Thank you, even if i seen this late but that was the issue, i changed the callings a bit so the isPurchased goes straight to the products as well, added logics with it and added the “return” part which fixed everthing

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.