I am making a Robux Shop where you can buy the game currency (stars) with robux. I am not really good at scripting with the MarketplaceService, so I used the ProcessReceipt from the Developer Hub.
It worked perfectly a few days ago, but now it keeps giving me this error: “Error occurred while processing a product purchase”
Here is the script:
Script
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
-- Data store for tracking purchases that were successfully processed
-- Table setup containing product IDs and functions for handling purchases
local productFunctions = {}
-- ProductId 123123 for a full heal
productFunctions[1215198990] = function(receipt, player)
-- Logic/code for player buying a full heal (may vary)
if player.Character and player.Character:FindFirstChild("Humanoid") then
require(game.ReplicatedStorage.TweenModule):tween(player.stars, {Value = (player.stars.Value + 10000)})
return true
end
end
productFunctions[1215199705] = function(receipt, player)
-- Logic/code for player buying a full heal (may vary)
if player.Character and player.Character:FindFirstChild("Humanoid") then
require(game.ReplicatedStorage.TweenModule):tween(player.stars, {Value = (player.stars.Value + 100000)})
return true
end
end
productFunctions[1215199924] = function(receipt, player)
-- Logic/code for player buying a full heal (may vary)
if player.Character and player.Character:FindFirstChild("Humanoid") then
require(game.ReplicatedStorage.TweenModule):tween(player.stars, {Value = (player.stars.Value + 1000000)})
return true
end
end
--[[productFunctions[1215200472] = function(receipt, player)
-- Logic/code for player buying a full heal (may vary)
if player.Character and player.Character:FindFirstChild("Humanoid") then
require(game.ReplicatedStorage.TweenModule):tween(player.stars, {Value = (player.stars.Value + 10000000)})
return true
end
end
]]
-- The core 'ProcessReceipt' callback function
local function processReceipt(receiptInfo)
-- Determine if the product was already granted by checking the data store
local playerProductKey = receiptInfo.PlayerId .. "_" .. receiptInfo.PurchaseId
local purchased = false
-- Find the player who made the purchase in the server
local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)
if not player then
-- The player probably left the game
-- If they come back, the callback will be called again
return Enum.ProductPurchaseDecision.NotProcessedYet
end
-- Look up handler function from 'productFunctions' table above
local handler = productFunctions[receiptInfo.ProductId]
-- Call the handler function and catch any errors
local success, result = pcall(handler, receiptInfo, player)
if not success or not result then
warn("Error occurred while processing a product purchase")
print("\nProductId:", receiptInfo.ProductId)
print("\nPlayer:", player)
return Enum.ProductPurchaseDecision.NotProcessedYet
end
-- IMPORTANT: Tell Roblox that the game successfully handled the purchase
return Enum.ProductPurchaseDecision.PurchaseGranted
end
-- Set the callback; this can only be done once by one script on the server!
MarketplaceService.ProcessReceipt = processReceipt
Thanks,
doctorpepper126