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:

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

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

01local MarketplaceService = game:GetService("MarketplaceService")
02 
03local 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
18end
19 
20MarketplaceService.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