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

how to check when a player buys an item (?)

Asked by 3 years ago

so this is the code im using

local player
script.Parent.MouseButton1Click:Connect(function()
    local MarketplaceService = game:GetService("MarketplaceService")
    local productID = 994379939
    player = script.Parent.Parent.Parent.Parent.Parent
    print(player)
    MarketplaceService:PromptProductPurchase(player,productID)
end)

when a player clicks on it and make a purchases i dont know how to see when a player makes the purchases the code i want it to run when a player buys it is this:

player.leaderstats.lives.Value = player.leaderstats.lives.Value + 10
0
Is this a product or gamepass? nekosiwifi 398 — 3y
0
a product botw_legend 502 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago

Use the PromptProductPurchaseFinished event.

local player
script.Parent.MouseButton1Click:Connect(function()
    local MarketplaceService = game:GetService("MarketplaceService")
    local productID = 994379939
    player = script.Parent.Parent.Parent.Parent.Parent
    print(player)
    MarketplaceService:PromptProductPurchase(player,productID)

    MarketplaceService.PromptProductPurchaseFinished:Connect(function(player, productID, isPurchased) -- isPurchased is a bool value which tells you whether or not the player purchased the product
        if isPurchased == true then -- if player purchased the product
            -- fire a RemoteEvent here to change the player's leaderstats value in a server script
        else
            print("Player did not purchase product")
        end
    end)
end)
Ad

Answer this question