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

How do I add to a value when a player purchases a developer product?

Asked by
Nickelz 37
6 years ago

I've made a GUI where you can purchase coins, and it has multiple choices for the number of coins you want to buy and when the user picks the one he wants, let's say 500 coins, it will cost 10r$, I have that part down, but I cannot figure out how to process the transaction by adding 500 coins.

The script prompting the purchase:

local MPS = game:GetService("MarketplaceService")
local PL = game:GetService("Players")
local player = PL.LocalPlayer
script.Parent.MouseButton1Click:connect(function()
            MPS:PromptProductPurchase(player, 429634850)
end)

1 answer

Log in to vote
0
Answered by
HaveASip 494 Moderation Voter
6 years ago
Edited 6 years ago

Instance a script into serverscriptservice and type in

When you purchased, you need to handle it on server script. Purchase grant can't be added automatically

You can read about product handling more here

local MarketplaceService = game:GetService("MarketplaceService")

local function processReceipt(receiptInfo)

    -- Find the player who made the purchase in the server
    local player = game:GetService("Players"):GetPlayerByUserId(receiptInfo.PlayerId)
    if not player then
        -- The player probably left the game
        -- If they come back, the callback will be called again
        return Enum.ProductPurchaseDecision.NotProcessedYet
    end

    -- Output what product they bought
    print(receiptInfo.PlayerId .. " just bought " .. receiptInfo.ProductId)

    --  Tell Roblox that the game successfully handled the purchase
    return Enum.ProductPurchaseDecision.PurchaseGranted
end

MarketplaceService.ProcessReceipt = processReceipt
0
Do you put the give coin script where it says print??? danglt 185 — 6y
0
No, it is on line 17. Line 14 is useless, so you can delete that line. I put print for test HaveASip 494 — 6y
Ad

Answer this question