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)
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)
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