Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

SkipStage script works only with one button but not another?

I have an obby and there is a shop where you can buy a skip 1 stage, skip 3 stages, skip 5 stages or skip 10 stages. When I try to buy the skips, only one works... Here is the local script for the Gui:

 local productId = 1051600749
 local player = game.Players.LocalPlayer
 script.Parent.MouseButton1Click:connect(function()
 	game:GetService("MarketplaceService"):PromptProductPurchase(player, productId)
 end)

Here is the script that I put in "ServerScriptStorage":

local MarketplaceService = game:GetService("MarketplaceService")
local currency = "Stage"
MarketplaceService.ProcessReceipt = function(receiptInfo)
    local player = game:GetService("Players"):GetPlayerByUserId(receiptInfo.PlayerId)
    if not player then
        return Enum.ProductPurchaseDecision.NotProcessedYet 
    end
    if receiptInfo.ProductId == 1051600749 then 
        print("Correct receipt")
        local leaderstats = player:findFirstChild("leaderstats")
        if leaderstats then 
            print("Found leaderstats")
            local currency = leaderstats:findFirstChild(currency)
            if currency then 
                print("Found currency")
                currency.Value = currency.Value + 1
                player:LoadCharacter()
            end
        end
    end
    return Enum.ProductPurchaseDecision.PurchaseGranted 
end

For every scripts, I changed the DeveloperProductId and the Value of the checkpoint to add. When I try to buy the SkipStage that doesn't work, it doesn't print anything that I put in the script... (sorry for the spelling mistakes, English is not my native language)
What's wrong with these scripts ?

1 answer

✓ Accepted answer

You can assign only one function to ProcessReceipt, meaning that you cant have multiple scripts with other functions assigned to ProcessReceipt. (i probably explained that horribly)

Make sure you only have one script using ProcessReceipt. To add other productids, you could use elseif.

if receiptInfo.ProductId == 1051600749 then
print("He bought coins")
elseif receiptInfo.ProductId == 9430429462 then
print("He bought gems")

This discussion is preserved as it was. New answers, comments, and votes are closed.