Hey, I’m trying to create a donation system and I am using processreceipt to make sure everything is processed properly and the player recieves their +100 robux on the donation leaderboard
I’m using the same structure as the roblox developer hub has described but it seems to, well not work.
Getting the error “Error occurred while processing a product purchase” which is a custom error message within the function
Server Script
local MarketplaceService = game:GetService("MarketplaceService")
local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")
local DonationData = DataStoreService:GetDataStore(require(game:GetService("ReplicatedStorage").MocaexData).DonationData)
local DonationPrice = 100
local purchaseHistoryStore = DataStoreService:GetDataStore("PurchaseHistory")
local productFunctions = {}
productFunctions[1151407393] = function(receipt, player)
-- Donation
Donations = nil
local success, errorMessage = pcall(function()
Donations = DonationData:GetAsync(player.UserId.."Donations")
end)
if success then
local dn = Donations + DonationPrice
local success, errorMessage = pcall(function()
purchaseHistoryStore:SetAsync(player.UserId.."Donations", dn)
end)
else
game:GetService("ReplicatedStorage").Events.NotifyStaff("We had trouble processing "..player.Name.."'s Donation datastore request")
end
end
local function processReceipt(receiptInfo)
local player = "Hi"
for _, Player in ipairs(game:GetService("Players"):GetChildren()) do
if Player.UserId == receiptInfo.PlayerId then
player = Player
end
end
--print("ProductId:", receiptInfo.ProductId)
print("Player:", player.Name)
local playerProductKey = receiptInfo.PlayerId .. "_" .. receiptInfo.PurchaseId
local purchased = false
local success, errorMessage = pcall(function()
purchased = purchaseHistoryStore:GetAsync(playerProductKey)
end)
if success and purchased then
return Enum.ProductPurchaseDecision.PurchaseGranted
elseif not success then
error("Data store error:" .. errorMessage)
end
if not player then
return Enum.ProductPurchaseDecision.NotProcessedYet
end
local handler = productFunctions[receiptInfo.ProductId]
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
local success, errorMessage = pcall(function()
purchaseHistoryStore:SetAsync(playerProductKey, true)
end)
if not success then
error("Cannot save purchase data: " .. errorMessage)
end
return Enum.ProductPurchaseDecision.PurchaseGranted
end
MarketplaceService.ProcessReceipt = processReceipt