Example on ProcessReceipt will never process any product purchase

https://developer.roblox.com/en-us/api-reference/callback/MarketplaceService/ProcessReceipt

I feel this is another fairly serious problem with example documentation on the Developer Hub as it will make new creators, who may have little knowledge of scripting, unable to gain any revenue from developer products without altering the script first.

The example given on the Developer Hub will never actuall process any purchase, because the way the example is written it is destined to error regardless of the circumstances. The error occurrs only after purchasing a product, when ensuring the product’s purchase hasn’t already been processed:

	local playerProductKey = receiptInfo.PlayerId .. "_" .. receiptInfo.PurchaseId
	local purchased = false
	local success, errorMessage = pcall(function()
		purchased = purchaseHistoryStore:GetAsync(playerProductKey)
	end)
	-- If purchase was recorded, the product was already granted
	if success and purchased then
		return Enum.ProductPurchaseDecision.PurchaseGranted
	else
		error("Data store error:" .. errorMessage)
	end

As you can see, the script will never go beyond these lines as if the produce has (somehow) been purchased and processed already, it will return PurchaseGranted. Otherwise, it will proceed to error - either an actual data store error, or an error stating that errorMessage is a nil value like so:


The error appears on a different line in my example as I have edited the script to work for a test developer product, and I have removed some lines!

The error should only ever be displayed if there actually is an errorMessage value. The example’s line 44 should be changed to:

elseif not success then

This will avoid an error being thrown if there wasn’t actually any error thrown in the pcall code.
Also, shouldn’t it really be a ypcall instead of pcall since GetAsync is a yielding function?

1 Like

Thanks for bringing this to our attention! The code sample is fixed now.

2 Likes

This problem is back:

No, roblox made it so pcall can yield just like ypcall a while ago.

1 Like

I believe the problem is no longer present, unless I’m missing something. If you’re still seeing this error, perhaps try to clear your cache?

Thanks for letting me know, I had seen multiple examples of where pcall was used despite the enclosed function yielding so I was a bit confused, this clears that up.

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