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

how can i debounce this dev product processor?

Asked by 7 years ago
Edited 7 years ago

i have tried everything but for some reason this doesn't work... does anyone know the problem? i got this from the wiki, because i am so bad at scripting :/

local MarketplaceService = game:GetService("MarketplaceService")
local PurchaseHistory = 

game:GetService("DataStoreService"):GetDataStore("PurchaseHistory")

local Products = {
    [] = function(receipt,player)
        local stage = player.leaderstats.Stage.Value
        if stage < 250
            then 
            player.leaderstats.Stage.Value = player.leaderstats.Stage.Value + 1
        end
        player.Character.Head:Destroy()
    end;
    [] = function(receipt,player)
        local stage = player.leaderstats.Stage.Value
        if stage < 250
            then 
            player.leaderstats.Stage.Value = player.leaderstats.Stage.Value + 5
        end
        player.Character.Head:Destroy()
    end;
    [] = function(receipt,player)
        local stage = player.leaderstats.Stage.Value
        if stage < 250
            then 
            player.leaderstats.Stage.Value = player.leaderstats.Stage.Value + 10
        end
        player.Character.Head:Destroy()
    end;
}

-- set MarketplaceService.ProcessReceipt to this function
-- (this is the same as doing: MarketplaceService.ProcessReceipt = function(recei... )
Off = false
function MarketplaceService.ProcessReceipt(receiptInfo)
   if not Off then
    Off = true
    local playerProductKey = receiptInfo.PlayerId .. ":" .. receiptInfo.PurchaseId
    if PurchaseHistory:GetAsync(playerProductKey) then
    Off = false
return Enum.ProductPurchaseDecision.PurchaseGranted --We already granted it.
end
end







function MarketplaceService.ProcessReceipt(receiptInfo)
    local playerProductKey = receiptInfo.PlayerId .. ":" .. receiptInfo.PurchaseId
    if PurchaseHistory:GetAsync(playerProductKey) then
        return Enum.ProductPurchaseDecision.PurchaseGranted --We already granted it.
   end

    -- find the player based on the PlayerId in receiptInfo
    local player,handler -- handler is used a few lines lower
    for k,v in ipairs(game:GetService("Players"):GetPlayers()) do
        if v.userId == receiptInfo.PlayerId then
            player = v break -- we found him, no need to search further
        end 
    end

    -- player left? not sure if it can happen, but to be sure, don't process it
    if not player then return Enum.ProductPurchaseDecision.NotProcessedYet end

    for productId,func in pairs(Products) do
        if productId == receiptInfo.ProductId then
            handler = func break -- found our handler
        end

   end

    -- apparently it's not our responsibility to handle this purchase
    -- if this happens, you should probably check your productIds etc
    -- let's just assume this is ment behavior, and let the purchase go through
    if not handler then return Enum.ProductPurchaseDecision.PurchaseGranted end

    -- call it safely with pcall, to catch any error
    local suc,err = pcall(handler,receiptInfo,player)
    if not suc then
        warn("An error occured while processing a product purchase")
        print("\t ProductId:",receiptInfo.ProductId,"\n","Player:",player)
        print("\t Error message:",err) -- log it to the output
        return Enum.ProductPurchaseDecision.NotProcessedYet
    end

    -- if the function didn't error, 'err' will be whatever the function returned
    -- if our handler didn't return anything (or it returned false/nil), it means
    -- that the purchase failed for some reason, so we have to cancel it
    if not err then
        return Enum.ProductPurchaseDecision.NotProcessedYet
    end

    -- record the transaction in a Data Store
    suc,err = pcall(function()
        PurchaseHistory:SetAsync(playerProductKey, true)
    end)
    if not suc then
        print("An error occured while saving a product purchase")
        print("\t ProductId:",receiptInfo.ProductId,"\n","Player:",player)
        print("\t Error message:",err) -- log it to the output
        print("\t Handler worked fine, purchase granted") -- add a small note that the actual purchase has succeed
    end
    -- tell ROBLOX that we have successfully handled the transaction (required)
    return Enum.ProductPurchaseDecision.PurchaseGranted     
end
end
end
0
put it ALL in a code block so I may look at it next time iamnoamesa 674 — 7y
0
sorry fixed Coconutko -2 — 7y
0
http://wiki.roblox.com/index.php?title=API:Class/MarketplaceService/ProcessReceipt "Setting this callback multiple times will overwrite the previous one" User#5423 17 — 7y

Answer this question