Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Where Can I Check Who Bought My Developer Product?

Asked by 3 years ago

I'm trying to make a script that keeps track of who bought my developer product. I have this script, but I'm not sure where to see who bought it.

local MarketplaceService = game:GetService("MarketplaceService")
local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")


local purchaseHistoryStore = DataStoreService:GetDataStore("PurchaseHistory")

local productFunctions = {}

productFunctions[1010354831] = function(receipt, player)
            wait(1)
        return true
    end

local function processReceipt(receiptInfo)

    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

    local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)
    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

2 answers

Ad
Log in to vote
0
Answered by 3 years ago

Solved on discord.

Answer this question