So I’ve got this script to handle my products. But I don’t really understand how the receipt function works. I assume that there is a way to track all purchases of x player. Like if I wanted to track purchases from a player named “Bob101” how would I do that? Thank you.
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local productFunctions = {}
-- buy 100 stars
productFunctions[1504961992] = function(receipt, player)
if player.Character and player.Character:FindFirstChild("Humanoid") then
print("Give stars")
player.PlayerData.Stars.Value += 100
-- Indicate a successful purchase
return true
end
end
local function processReceipt(receiptInfo)
local userId = receiptInfo.PlayerId
local productId = receiptInfo.ProductId
local player = Players:GetPlayerByUserId(userId)
if player then
-- Get the handler function associated with the developer product ID and attempt to run it
local handler = productFunctions[productId]
local success, result = pcall(handler, receiptInfo, player)
if success then
-- The player has received their benefits!
-- return PurchaseGranted to confirm the transaction.
return Enum.ProductPurchaseDecision.PurchaseGranted
else
warn("Failed to process receipt:", receiptInfo, result)
end
end
-- the player's benefits couldn't be awarded.
-- return NotProcessedYet to try again next time the player joins.
return Enum.ProductPurchaseDecision.NotProcessedYet
end
-- Set the callback; this can only be done once by one script on the server!
MarketplaceService.ProcessReceipt = processReceipt