Hey! So I made developer products that are supposed to give cash to a player in the game.
When you click the button, and buy the developer product, nothing happens.
Here’s the script that I have:
local MarketplaceService = game:GetService("MarketplaceService")
local players = game:GetService("Players")
local SG = game:GetService("StarterGui")
local productID = 1347531300
local function processReceipt(receiptInfo)
local player = players:GetPlayerByUserId(receiptInfo.PlayerId)
if not player then
return Enum.ProductPurchaseDecision.NotProcessedYet
end
if player then -- Rewards
game.Players.PlayerAdded:Connect(function(player)
local cash = game.Players.LocalPlayer:WaitForChild("leaderstats"):WaitForChild("Cash")
cash.Value = cash.Value * 10
end)
end
end
MarketplaceService.ProcessReceipt = processReceipt
local MarketplaceService = game:GetService("MarketplaceService")
local players = game:GetService("Players")
local SG = game:GetService("StarterGui")
local productID = 1347531300
local function processReceipt(receiptInfo)
local player = players:GetPlayerByUserId(receiptInfo.PlayerId)
if not player then
return Enum.ProductPurchaseDecision.NotProcessedYet
end
if player then -- Rewards
if receiptInfo.ProductId == productId then
local cash = player:WaitForChild("leaderstats"):WaitForChild("Cash")
cash.Value = cash.Value * 10
end
end
end
MarketplaceService.ProcessReceipt = processReceipt
This works for a game with only one devproduct, a better solution is to have a dictionary, the key being the id, and the value being a function to use the product, like in the docs.
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
products = {}
products[1347531300] = function(receipt, player)
-- Multiplies a player's cash by a factor of 10
local cash = player:WaitForChild("leaderstats"):WaitForChild("Cash")
cash.Value = cash.Value * 10
end
local function processReceipt(receiptInfo)
local userId = receiptInfo.PlayerId
local productId = receiptInfo.ProductId
local player = Players:GetPlayerByUserId(userId)
if not player then
return Enum.ProductPurchaseDecision.NotProcessedYet
end
local handler = productFunctions[productId]
local success, result = pcall(handler, receiptInfo, player)
if success then
return Enum.ProductPurchaseDecision.PurchaseGranted
else
warn("Failed to process receipt:", receiptInfo, result)
return Enum.ProductPurchaseDecision.NotProcessedYet
end
end
MarketplaceService.ProcessReceipt = processReceipt
This makes it really easy to add more products and fix any bugs in existing ones.