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 3 years ago
Edited 3 years ago
local mps = game:GetService("MarketplaceService")
game.Players.PlayerAdded:Connect(function(player)
    game.Workspace.SellCoins1000.SurfaceGui.Buy1000.MouseButton1Click:Connect(function()
            local productId = 1086368295
        game:GetService("MarketplaceService"):PromptProductPurchase(player, productId)
        mps.ProcessReceipt = function(receiptInfo)
            if receiptInfo == productId then
                player(receiptInfo.playerId)
                player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 1000
                return Enum.ProductPurchaseDecision.PurchaseGranted
            end
        end
        end)

    end)

1 answer

Log in to vote
0
Answered by
zane21225 243 Moderation Voter
3 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.

-- Variables:
local marketplaceService = game:GetService('MarketplaceService')
local productId = 1086368295

local part = workspace:WaitForChild('SellCoins1000')
local button = part:WaitForChild('Buy1000')

local statsGain = 1000

-- onClicked Function:
local function promptPurchase(player)
    if not marketplaceService:UserOwnsGamePassAsync(player.UserId, productId) then --Making sure the player doesn't already own the game pass
        marketplaceService:PromptGamePassPurchase(player, productId)
        marketplaceService.PromptGamePassPurchaseFinished:Connect(function(player, purchasedId, bought)
            if purchasedId == productId and bought == true then
                print(player .. 'has successfully purchased something!')
                player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + statsGain
            end
        end)
    end
end
Ad

Answer this question