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

I need someone to explain on how the Developer product works?

I looked at the wiki, did some testing, and I can't figure it out like I usually would.

Since I am making a purchasable product in a Gui, It's client side.. When they click [Buy] for example, how would it appear so that they can purchase, then it does whatever I want?

Any help would be appreciated except a link, thanks anyway

1 comment

0

I know you don't want links but they have the code right there on the Developer Product page on the wiki and you can also check out the sample place to get an example.

1 answer

Developer Product Info

Developer Products in roblox are essentially re-purchasable GamePasses. To make one do what you want, you have to use the ProcessReceipt Callback of MarketplaceService.



ProcessReceipt Info

The ProcessReceipt Callback takes in a function! You have to define a function to the ProcessReceipt for it to work. It acts similiar to an event, it's a listener.. for whenever a DeveloperProduct is purchased. But unlike an event, it is not redefinable. You cannot define multiple ProcessReceipts and expect it to work. If you redefine a ProcessReceipt then it will just be overwritten.


The function that you tie to ProcessReceipt should have one parameter, because ProcessReceipt returns a value.. which is inofficially known as 'receiptInfo'. The receiptInfo has all the information about the Purchase of said Developer Product in a dictionary.

What receiptInfo contains

  • PlayerId

PlayerId is the userId of the player that bought the Product

  • PlaceIdWherePurchased

PlaceIdWherePurchased is the game ID of where the Product was bought, useful for universes.

  • PurchaseId

PurchaseId is a unique identifier for the purchase which is used to prevent granting an item multiple times for one purchase

  • ProductId

ProductId is the asset ID of whatever product was bought.. used if a game has multiple Products.

  • CurrencyType

CurrencyType is the type of currency spent on the Product(Robux or Tix).

  • CurrencySpent

CurrencySpent is the amount of [CurrencyType] that was spent


Mostly, the only things that you will have to use are ProductId, to tell what product was bought, and PlayerId, to tell which player bought the Product.



How To Make A Working ProcessReceipt

You need to first.. find the player that bought the pass by iterating through all players and comparing receiptInfo.PlayerId.

Then, you need to see what product was bought by comparing receiptInfo.ProductId with a predefined ID.

After that, award said player with whatever you want.

And lastly, you must return Enum.ProductPurchaseDecision.PurchaseGranted, in order to gain any money from the purchase.



Code

local id = 0000000 --ID of product
local ms = game:GetService('MarketplaceService') --MarketplaceService

--ProcessReceipt
ms.ProcessReceipt = function(receiptInfo)
	--predefine 'plr' variable
	local plr
	--Iterate through players
	for i,v in pairs(game.Players:GetPlayers())
		--Compare userId with PlayerId
		if v.userId == receiptInfo.PlayerId then
			--Set 'plr' variable
			plr = v
		end
	end
	--Check ProductID
	if receiptInfo.ProductId == id then
		
		--[[ AWARD PLAYER ]]--
		
		--Get your money
		return Enum.ProductPurchaseDecision.PurchaseGranted
	end
end

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