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.
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)
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.
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