I added the server script to ServerScriptService. I confirmed that the Badge and Developer product IDs are correct. However, I will not receive the contributor badge after making a donation in the game. Can someone point me in the right direction. I am not receiving an error message in the output window.
-- Marketplace Service --
local MarketplaceService = game:GetService("MarketplaceService")
local BadgeService = game:GetService("BadgeService")
local ContributorBadge = 273973985081904
local ProductTable = {
ProductId = {
1792712917,
1792713903,
1792714392,
1792718870
}
}
local function processReceipt(receiptInfo)
local Player = game:GetService("Players"):GetPlayerByUserId(receiptInfo.PlayerId)
if not Player then
print("Player cannot be located.")
return Enum.ProductPurchaseDecision.NotProcessedYet
end
if Player then
print("Found player.")
if receiptInfo.ProductId == ProductTable.ProductId then
if BadgeService:UserHasBadgeAsync(Player.UserId, ContributorBadge) then
else
print(Player.Name.." donated robux and received the Contributor badge at "..receiptInfo.ProductId)
BadgeService:AwardBadge(Player.UserId, ContributorBadge)
end
end
end
return Enum.ProductPurchaseDecision.PurchaseGranted
end
MarketplaceService.ProcessReceipt = processReceipt
Thanks for the advice, but unfortunately, The badge was not awarded to me after making a donation. There are no errors in the developer console either.
It might be to do with :UserHasBadgeAsync() and it halting the script. I’ve found hitting this too much leads to errors due to rate limiting so I usually just force the :AwardBadge regardless and surround it in a pcall, so if an error occurs, it won’t completely break the ProcessReceipt process.
Try this:
-- Marketplace Service --
local MarketplaceService = game:GetService("MarketplaceService")
local BadgeService = game:GetService("BadgeService")
local ContributorBadge = 273973985081904
local ProductIdTable = {
1792712917,
1792713903,
1792714392,
1792718870
}
local function processReceipt(receiptInfo)
local Player = game:GetService("Players"):GetPlayerByUserId(receiptInfo.PlayerId)
if not Player then
print("Player cannot be located.")
return Enum.ProductPurchaseDecision.NotProcessedYet
end
if Player then
print("Found player.")
if table.find(ProductIdTable, receiptInfo.ProductId) then
--[[
For the amount of time, and possibly the rate limit of UserHasBadgeAsync,
it's probably worth just wrapping :AwardBadge around a pcall to silence any error if the player
already has the badge.
]]
local success, err = pcall(function()
BadgeService:AwardBadge(receiptInfo.UserId, ContributorBadge)
end)
--[[
Use (success: boolean) or (err: error data) here if you want to catch a failure of AwardBadge and do
something with it.
]]
end
end
return Enum.ProductPurchaseDecision.PurchaseGranted
end
MarketplaceService.ProcessReceipt = processReceipt