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

prompting product purchase on surface gui not working?

Asked by 4 years ago
Edited 4 years ago
01local mps = game:GetService("MarketplaceService")
02game.Players.PlayerAdded:Connect(function(player)
03    game.Workspace.SellCoins1000.SurfaceGui.Buy1000.MouseButton1Click:Connect(function()
04            local productId = 1086368295
05        game:GetService("MarketplaceService"):PromptProductPurchase(player, productId)
06        mps.ProcessReceipt = function(receiptInfo)
07            if receiptInfo == productId then
08                player(receiptInfo.playerId)
09                player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 1000
10                return Enum.ProductPurchaseDecision.PurchaseGranted
11            end
12        end
13        end)
14 
15    end)

1 answer

Log in to vote
0
Answered by
zane21225 243 Moderation Voter
4 years ago

Hello!

I am assuming the issue here lies simply in the Functions you are using via the MarketplaceService.

I did some organizing & redoing of your code!

I'm assuming that you are prompting purchase of a Developer Product or a Game Pass (within the game), so here is the code that should work for that.

01-- Variables:
02local marketplaceService = game:GetService('MarketplaceService')
03local productId = 1086368295
04 
05local part = workspace:WaitForChild('SellCoins1000')
06local button = part:WaitForChild('Buy1000')
07 
08local statsGain = 1000
09 
10-- onClicked Function:
11local function promptPurchase(player)
12    if not marketplaceService:UserOwnsGamePassAsync(player.UserId, productId) then --Making sure the player doesn't already own the game pass
13        marketplaceService:PromptGamePassPurchase(player, productId)
14        marketplaceService.PromptGamePassPurchaseFinished:Connect(function(player, purchasedId, bought)
15            if purchasedId == productId and bought == true then
View all 21 lines...
Ad

Answer this question