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
Also, shouldn’t it really be a
ypcall instead of
pcall since GetAsync is a yielding function?