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

How would I Convert a Script for 1 developer product purchase into a multi product purchase script?

Asked by 7 years ago
Edited 7 years ago

So I have recently created several more developer product purchases that do the same thing as my first one but more lives. I was trying to convert it over to the multi developer product purchase script to get them all working since it obviously breaks all but the last one in this script if I repeat it. I tried multiple times to convert it and was just wondering if anyone could help me with the conversion.

Here is a portion of my current script for just one developer product purchase since the rest would be a copy of the conversion with different values.

local mpService = game:GetService("MarketplaceService")

mpService.ProcessReceipt = function(purchaseInfo)
    local plr = game:GetService("Players"):GetPlayerByUserId(purchaseInfo.PlayerId)
    if not plr then
        return Enum.ProductPurchaseDecision.NotProcessedYet
    end

    if purchaseInfo.ProductId == 55131820 then
        local Lives = plr.leaderstats.Souls;
        Lives.Value = Lives.Value +1
    end

    return Enum.ProductPurchaseDecision.PurchaseGranted
end

and Here is a portion of the multi developer product purchase script from the wiki.

local Products = {
    -- productId 1111 for a heal up
    [1111] = function(receipt,player)
        -- Check if we can actual heal him
        if not player.Character then return end
        local human = player.Character:findFirstChild("Humanoid")
        if not human then return end
        -- Heal him, and return true, indicating the purchase is done
        human.Health = human.MaxHealth
        return true
    end;
    -- productId 2222 for 100 gold
    [2222] = function(receipt,player)
        -- again, do checks, this time for the Gold value
        local stats = player:findFirstChild("leaderstats")
        local gold = stats and stats:findFirstChild("Gold")
        if not gold then return end -- no leaderstats, or "Gold" in them
        gold.Value = gold.Value + 100 -- give gold
        return true -- tell them of our success
    end;

I tried changing the

local stats = player:findFirstChild("leaderstats")
        local gold = stats and stats:findFirstChild("Gold")
        if not gold then return end -- no leaderstats, or "Gold" in them
        gold.Value = gold.Value + 100 -- give gold

portion of the script to my values but with no such luck. Anyone who can help would be greatly appreciated.

0
What's a developer option? User#15029 30 — 7y
0
It's a option you can use by: Games/Places, Gamepasses, Products, Decals, Assets, Animations & more. It have a option between and for all these Dev things. If you like to know more then tell me. MineJulRBX 52 — 7y
0
@minecraftjul are you sure this person doesn't mean developer product? User#15029 30 — 7y
0
I do mean developer product SocialENTRcoRSE 21 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago

Without setting up a dictionary, you can simply just add elseif statements to check for multiple IDs like so:

local mpService = game:GetService("MarketplaceService")

mpService.ProcessReceipt = function(purchaseInfo)
    local plr = game:GetService("Players"):GetPlayerByUserId(purchaseInfo.PlayerId)
    if not plr then
        return Enum.ProductPurchaseDecision.NotProcessedYet
    end

    if purchaseInfo.ProductId == 55131820 then
        local Lives = plr.leaderstats.Souls;
        Lives.Value = Lives.Value +1
    elseif purchaseInfo.ProductId == 40592456 then
        local Lives = plr.leaderstats.Souls;
        Lives.Value = Lives.Value +2
    elseif purchaseInfo.ProductId == 50123452 then
        local Lives = plr.leaderstats.Souls;
        Lives.Value = Lives.Value +3
    end

    return Enum.ProductPurchaseDecision.PurchaseGranted
end

Hope this helps and you can continue on adding more with these examples. If it doesn't work or you need help, comment below. If it's perfectly fine then just accept it as the answer and upvote of you feel like it!

0
Thank you so much! I don't know why I overlooked that but, it's always good to get an outside perspective. Now I can finally start implementing my DataStores to keep track of my purchases. SocialENTRcoRSE 21 — 7y
0
Also I would absolutely upvote you but I don't have 25 reputation yet to accomplish that. SocialENTRcoRSE 21 — 7y
Ad

Answer this question