So I have some Developer Products, but when I test the purchase I get the warning (set in the script in case of failure) Failed to process receipt: ▶ {...} Unable to cast value to Object. I use the default dev product handler script. When bought, a RemoteEvent should be fired. Note that the 2nd argument has not been used in other use cases of this event. Idk if that matters but it’s info I guess
The scripts in question:
DevProductHandler
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local productFunctions = {}
--MAIN (001 and 002 are placeholders to simplify answers in this post)
productFunctions[001] = function(receipt, player)
game:GetService("ReplicatedStorage").Events.Start:FireClient(true, true)
return true
end
productFunctions[002] = function(receipt, player)
game:GetService("ReplicatedStorage").Events.Start:FireClient(true, true)
return true
end
local function processReceipt(receiptInfo)
local userId = receiptInfo.PlayerId
local productId = receiptInfo.ProductId
local player = Players:GetPlayerByUserId(userId)
if player then
-- Gets the handler function associated with the developer product ID and attempts to run it
local handler = productFunctions[productId]
local success, result = pcall(handler, receiptInfo, player)
if success then
-- The user has received their items
-- Returns "PurchaseGranted" to confirm the transaction
return Enum.ProductPurchaseDecision.PurchaseGranted
else
warn("Failed to process receipt:", receiptInfo, result)
end
end
-- The user's items couldn't be awarded
-- Returns "NotProcessedYet" and tries again next time the user joins the experience
return Enum.ProductPurchaseDecision.NotProcessedYet
end
-- Sets the callback
-- This can only be done once by one server-side script
MarketplaceService.ProcessReceipt = processReceipt
DevProductReceiver
--[[
This is not the full script, and I made a few changes to shortify it (such
as removing plenty of script.Parent.Parent.etc.
]]--
game:GetService("ReplicatedStorage").Events.Start.OnClientEvent:Connect(function(ignore, hasRevived)
if hasRevived then
revivesUsed += 1
task.wait()
score.Value = lastScore.Value
end
end)