Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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

2 comments

0

Do you put the give coin script where it says print???

0

No, it is on line 17. Line 14 is useless, so you can delete that line. I put print for test

This discussion is preserved as it was. New answers, comments, and votes are closed.