How to grant in-game rewards for real-world merch safely
PromptCommerceProductPurchaseFinished fires when the merch window closes, bought or not. How to bundle the reward as a developer product and grant it in ProcessReceipt.
What it looks like
The game sells real-world merchandise through CommerceService and gives an in-game reward with it, but hands the reward out when the purchase window closes, or when the client says the order went through. Roblox only sends a receipt for the reward when the order is paid.
CommerceService.PromptCommerceProductPurchaseFinished:Connect(function(player, productId) giveMerchCape(player) end)
What an exploiter could do
They open the merch window and close it, or fire the claim remote, and collect the reward without paying for anything. Rewards tied to merch are often exclusive, so this also takes away what real buyers paid for.
How to fix it
- Grant the reward only in
ProcessReceipt, from the bundled developer product's id, recording thePurchaseIdlike any other product. - Use
PromptCommerceProductPurchaseFinishedonly for the interface, such as closing the shop or putting the screen back the right way round on Android. - The client may ask the server to open the merch window, but no remote should grant the reward.
Vulnerable example
local CommerceService = game:GetService("CommerceService") local ReplicatedStorage = game:GetService("ReplicatedStorage") local PlayerData = require(script.Parent.PlayerData) local hoodie = "COM-1111111111" ReplicatedStorage.Remotes.BuyHoodie.OnServerEvent:Connect(function(player: Player) CommerceService:PromptCommerceProductPurchase(player, hoodie) end) CommerceService.PromptCommerceProductPurchaseFinished:Connect(function(player: Player, productId: string) local profile = PlayerData.get(player) if productId == hoodie and profile and not profile.Claimed.HoodieCape then profile.Claimed.HoodieCape = true table.insert(profile.Inventory, "HoodieCape") end end)
Fixed example
local CommerceService = game:GetService("CommerceService") local MarketplaceService = game:GetService("MarketplaceService") local Players = game:GetService("Players") local ReplicatedStorage = game:GetService("ReplicatedStorage") local PlayerData = require(script.Parent.PlayerData) local hoodie = "COM-1111111111" local hoodieCapeProduct = 1100030 ReplicatedStorage.Remotes.BuyHoodie.OnServerEvent:Connect(function(player: Player) CommerceService:PromptCommerceProductPurchase(player, hoodie) end) CommerceService.PromptCommerceProductPurchaseFinished:Connect(function(player: Player) ReplicatedStorage.Remotes.MerchClosed:FireClient(player) end) MarketplaceService.ProcessReceipt = function(receipt) if receipt.ProductId ~= hoodieCapeProduct then return Enum.ProductPurchaseDecision.NotProcessedYet end local player = Players:GetPlayerByUserId(receipt.PlayerId) local profile = player and PlayerData.get(player) if not profile then return Enum.ProductPurchaseDecision.NotProcessedYet end local key = "Purchase:" .. receipt.PurchaseId if not profile.Claimed[key] then profile.Claimed[key] = true table.insert(profile.Inventory, "HoodieCape") end return Enum.ProductPurchaseDecision.PurchaseGranted end
How to spot this in your own scripts, and the cases that only look like it, are part of the Luaudit check your AI runs.