How to give the player a badge after fully purchasing a Developer Product

I’m trying to make it so once someone buys a developer product (basically a donation) they’re awarded a badge called “Contributor”, however I’m running into an issue on how to actually do that.

I’ve already read this article

But I’m having trouble understanding it, and I feel like this isn’t what I’m supposed to do.

A point in the right direction would be nice on how to properly incorporate this. Thank you.

Here’s my code:

-- Marketplace Service --
local MarketplaceService = game:GetService("MarketplaceService")
local ProductId = 1180878512

-- Badge Service --
local BadgeService = game:GetService("BadgeService")
local BadgeId = 2124789267

local Player = script.Parent.Parent.Parent.Parent.Parent
local PlayerUserId = Player.UserId -- this was for something I attempted, don't worry about it.

script.Parent.MouseButton1Click:Connect(function()
	MarketplaceService:PromptProductPurchase(Player, ProductId)
end)
1 Like

award if player successfully buys it.

3 Likes

I know how to award the badge like this:

BadgeService:AwardBadge(Player.UserId, BadgeId)

But I don’t want someone to just interact with the prompt and already get it even though they didn’t even purchase it yet.

1 Like

How does one do this? Are you saying that when it says “PromptProductPurchase” it will pause until it’s purchased? I’m just confused.

For context:

script.Parent.MouseButton1Click:Connect(function()
	MarketplaceService:PromptProductPurchase(Player, ProductId)

    BadgeService:AwardBadge(Player.UserId, BadgeId)
end)
1 Like

You can check if its purchased, then award the badge. Instead of accidently awarding the badge, when the prompt goes up.

1 Like

The main question is, how do I go about checking if they actually bought the developer product? Sorry if the title didn’t explain that enough.

you’ll have to use process receipt function.

I suggest looking at a tutorial like this:

1 Like

https://developer.roblox.com/en-us/api-reference/callback/MarketplaceService/ProcessReceipt

1 Like

That video explained everything… I got confused because I thought it was an event somewhere that I needed but I’m supposed to plug the ProcessReceipt in with a function so each time someone buys it fires it, I can then check the Proper product so it doesn’t accidently give the badge, and so on. Thank you for showing that video. I’ve watched him before just never knew he covered that. If only the developer hub was a bit more informative.

To anyone curious on the script, here you go:

Thanks to @Juicy_Fruit for sending the tutorial, and thank you to everyone else who helped.

-- Marketplace Service --
local MarketplaceService = game:GetService("MarketplaceService")

-- Get the BadgeService --
local BadgeService = game:GetService("BadgeService")
local ContributorBadge = 2124789267

-- Product Table --
local ProductTable = {
	ProductId = 1180878512
}

local function processReceipt(receiptInfo)
	
	local Player = game:GetService("Players"):GetPlayerByUserId(receiptInfo.PlayerId)
	
	if not Player then
		print("Player cannot be located.")
		-- Return to roblox saying that the player left or never completed the transcation --
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end
	
	if Player then
		print("Found player.")
		-- Give the player goods depending on what they actually bought --
		if receiptInfo.ProductId == ProductTable.ProductId then
			if BadgeService:UserHasBadgeAsync(Player.UserId, ContributorBadge) then
				-- do nothing
			else
				print(Player.Name.." donated 15 robux and received the Contributor badge at "..receiptInfo.ProductId)
				BadgeService:AwardBadge(Player.UserId, ContributorBadge)
			end
		end
	end
	
	-- Kindly tell roblox they actually bought it so they don't get mad at me
	return Enum.ProductPurchaseDecision.PurchaseGranted

end

-- Set the callback so it doesn't scream at you
MarketplaceService.ProcessReceipt = processReceipt
6 Likes