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:
1 | local MPS = game:GetService( "MarketplaceService" ) |
2 | local PL = game:GetService( "Players" ) |
3 | local player = PL.LocalPlayer |
4 | script.Parent.MouseButton 1 Click:connect( function () |
5 | MPS:PromptProductPurchase(player, 429634850 ) |
6 | end ) |
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
01 | local MarketplaceService = game:GetService( "MarketplaceService" ) |
02 |
03 | local function processReceipt(receiptInfo) |
04 |
05 | -- Find the player who made the purchase in the server |
06 | local player = game:GetService( "Players" ):GetPlayerByUserId(receiptInfo.PlayerId) |
07 | if not player then |
08 | -- The player probably left the game |
09 | -- If they come back, the callback will be called again |
10 | return Enum.ProductPurchaseDecision.NotProcessedYet |
11 | end |
12 |
13 | -- Output what product they bought |
14 | print (receiptInfo.PlayerId .. " just bought " .. receiptInfo.ProductId) |
15 |
16 | -- Tell Roblox that the game successfully handled the purchase |
17 | return Enum.ProductPurchaseDecision.PurchaseGranted |
18 | end |
19 |
20 | MarketplaceService.ProcessReceipt = processReceipt |