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

How do I detect a Gamepass that is purchased ingame?

Asked by
Vxpper 101
5 years ago
Edited 5 years ago

I'm making a game and wanting a GUI to appear when they buy a certain gamepass. I found that MarketplaceService.PromptGamePassPurchaseFinished is a thing, I believe I'm using this incorrectly, how do I properly use this?

    local MarketplaceService = game:GetService("MarketplaceService")
    local DataStore2 = require(script.Parent:WaitForChild("MainModule"))
    local pid1 = 703927122
    local pid2 = 703927252
    local pid3 = 703927369
    local pid4 = 703927502
    local pid5 = 715997494

MarketplaceService.ProcessReceipt = function(receiptInfo) 
local newTable = bigCopy(plr)
local MasterData = DataStore2(currentData, plr)

    for i, player in ipairs(game.Players:GetChildren()) do
    if player.UserId == receiptInfo.PlayerId then                           
        if receiptInfo.ProductId == pid1 then                   
            wait(2)
            newTable.Coins = newTable.Coins + 1000
            player.PlayerGui.Main.Coins.Coin.AddedAmount.Visible = true
            player.PlayerGui.Main.Coins.Coin.AddedAmount.Text = "+1,000"
            wait(1)
            player.PlayerGui.Main.Coins.Coin.AddedAmount.Visible = false
            player.PlayerGui.Main.Coins.Coin.AddedAmount.Text = ""

        elseif receiptInfo.ProductId == pid2 then
            wait(2)
            newTable.Coins = newTable.Coins + 3000
            player.PlayerGui.Main.Coins.Coin.AddedAmount.Visible = true
            player.PlayerGui.Main.Coins.Coin.AddedAmount.Text = "+3,000"
            wait(1)
            player.PlayerGui.Main.Coins.Coin.AddedAmount.Visible = false
            player.PlayerGui.Main.Coins.Coin.AddedAmount.Text = ""

        elseif receiptInfo.ProductId == pid3 then
            wait(2)
            newTable.Coins = newTable.Coins + 7750
            player.PlayerGui.Main.Coins.Coin.AddedAmount.Visible = true
            player.PlayerGui.Main.Coins.Coin.AddedAmount.Text = "+7,750"
            wait(1)
            player.PlayerGui.Main.Coins.Coin.AddedAmount.Visible = false
            player.PlayerGui.Main.Coins.Coin.AddedAmount.Text = ""

        elseif receiptInfo.ProductId == pid4 then
            wait(2)
            newTable.Coins = newTable.Coins + 13500
            player.PlayerGui.Main.Coins.Coin.AddedAmount.Visible = true
            player.PlayerGui.Main.Coins.Coin.AddedAmount.Text = "+13,500"
            wait(1)
            player.PlayerGui.Main.Coins.Coin.AddedAmount.Visible = false
            player.PlayerGui.Main.Coins.Coin.AddedAmount.Text = ""

        elseif receiptInfo.ProductId == pid5 then               
            wait(2)
            purchaseItem:FireClient(player, "CrateGui")

        elseif MarketplaceService.PromptGamePassPurchaseFinished(7227010) then
            wait(1)
            vip:FireClient(player, "VIPSuccess")
end
end
    MasterData:Set(newTable)
    return Enum.ProductPurchaseDecision.PurchaseGranted 
end
end     
end)

2 answers

Log in to vote
0
Answered by
Farsalis 369 Moderation Voter
5 years ago
Edited 5 years ago

Since, PromptGamePassPurchaseFinished is an event you need to do the following.

local Market = game:GetService("MarketplaceService")

Market.PromptGamePassPurchaseFinished:Connect(function(...) -- Using connect to hook into the event with a function. Also, note the extra args, since this function returns PlayerName, GamePassId, and if the purchase succeeded(Bool, which can return false. Due to cancellations or errors.), in that order. 
    --Code Stuff
    print(...)
end)
--Or Connect With A Prior Function. Usually The Safest Route.
local function Process(...)
    --Code Stuff
    print(...)
end)

Market.PromptGamePassPurchaseFinished(Process)
0
Yeah but I'm wanting to add the benefits VIP members get instantly. Vxpper 101 — 5y
0
You could always reset the player....xD Farsalis 369 — 5y
0
sorry sorry, re editing Farsalis 369 — 5y
0
I am hoping to do this with multiple multiple gamepasses and would I put the gamepass idea inside of the :Connect(function()? Vxpper 101 — 5y
0
Yep, you got it. Farsalis 369 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

Try this:

marketPlace = game:GetService("MarketplaceService")

if marketplace:PlayerOwnsAsset(game.Players.LocalPlayer, [YOUR PRODUCT]) then
    -- Something happens
else
    warn("Player does not own the asset")
    -- Probably a script to prompt purchase
end

Answer this question