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

How do I make a button to buy a gamepass and change a leaderstat?

Asked by 9 years ago

I was trying to make a gui button to buy a game pass and when the game pass is bought it adds +1 to your stage. I couldn't get it to work, when you click it nothing happens. Is there something wrong with it? Can somebody help me? Here is the code:

local ITEM_ID = 244697986
local STAGE = script.Parent.Parent.Parent.Parent.leaderstats.Stage
local MarketplaceService = game:GetService("MarketplaceService")
local player = script.Parent.Parent.Parent.Parent

function onButtonClicked()
    if STAGE.Value == 47 then return end
MarketplaceService:PromptPurchase(ITEM_ID)
wait(.5)
if MarketplaceService:PlayerOwnAsset(player, ITEM_ID) then
STAGE.Value = STAGE.Value +1
wait(.1)
player.Character.Humanoid.Health = 0
wait(5.2)
script.Parent.Parent:remove()
end
end

script.Parent.MouseButton1Click:connect(onButtonClicked)

Please help me fix it! :(

1 answer

Log in to vote
0
Answered by 9 years ago

I changed a few things like added a listener for PromptPurchaseFinished" and instead of killing the "Humanoid" I just used the "BreakJoints" Method on the "Character".

local ITEM_ID = 244697986
local STAGE = script.Parent.Parent.Parent.Parent.leaderstats.STAGE
local MarketplaceService = game:GetService("MarketplaceService")
local player = script.Parent.Parent.Parent.Parent

MarketplaceService.PromptPurchaseFinished:connect(function(Player, assetId ,isPurchased) -- Listen for the sale...
    if isPurchased and Player == player and assetId == ITEM_ID then --if the player did pay...
        STAGE.Value = STAGE.Value + 1
        if player.Character then
            player.Character:BreakJoints() -- BreakJoints instead.
        end
    end
end)

function onButtonClicked()
    if STAGE.Value == 47 then return end
    MarketplaceService:PromptPurchase(ITEM_ID)
end

script.Parent.MouseButton1Click:connect(onButtonClicked)

I hope this helped!

0
Thx :D flamenathan327 20 — 9y
0
Np : ) TheDarkOrganism 173 — 9y
Ad

Answer this question