Need help understanding the Roblox developer products purchase script

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? I want to improve my understanding on the roblox marketplace developer products server script.

  2. What is the issue? Include screenshots / videos if possible! I don’t understand how the script works

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub? Yes

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

]local MarketPlaceService = game:GetService("MarketplaceService")

local DevProductId = 1267279630

local Player = game:GetService("Players")

local function ProcessDevProductReceipt(receiptInfo)
	local PlayerUserId = Player:GetPlayerByUserId(receiptInfo.PlayerId)
	
	if receiptInfo.ProductId == DevProductId then
		if PlayerUserId then
			print(PlayerUserId.Name .. " Has Bought the " .. receiptInfo.ProductId .. " Dev Product! ")
		end
	end
	
	if not PlayerUserId then
		-- Player Probably left the game or There is no Player so call the callback function incase they leave the game while purchasing the dev product
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end
	-- If Player this will return
	return Enum.ProductPurchaseDecision.PurchaseGranted
end

-- Callback

MarketPlaceService.ProcessReceipt = ProcessDevProductReceipt

Hi, so I’m posting this topic because I’m having a hard time understanding this marketplace service developer product server script i got from a YouTube tutorial even after watching the youtube tutorial i still don’t understand the script. Does anyone have experience with developer products that can help me understand this server script thank you for your help :slight_smile:

1 Like

Developer products are able to be purchased multiple times (for buying coins, etc)

What the code does here is it gets the Player from the receipt.

if the Player is not in the game it will return NotProcessedYet (Roblox will keep trying to fire ProcessReceipt until PurchasedGranted is returned or after 7 days the user gets their money back)

If the player is still in the game, you would put any handler code here (e.g. coin increase)

P.S. To properly handle developer products correctly (e.g. DataStores) is a little more complex but the explanation above should work for you.

1 Like