How to assign badge to more than one Developer Product purchase option?

I want players to be awarded a “Donator” badge regardless of which donation amount they select, but the script I use currently only supports one option. Please help!

-- // Services
local MarketPlace = game:GetService("MarketplaceService")
local BadgeService = game:GetService("BadgeService")

-- // Var
local ProductID = {
	2699503706,
	2699503784
}
local BadgeID = 4499076816490857

MarketPlace.PromptProductPurchaseFinished:Connect(function (Userid,Product_Id,Purchased)
	if Product_Id == ProductID and Purchased then
		if not BadgeService:UserHasBadgeAsync(Userid,BadgeID) then
			BadgeService:AwardBadge(Userid,BadgeID)
			print("earned donator badge!")
		end
	end
end)

Well, It’s really quite simple:

if Purchased and not BadgeService:UserHasBadgeAsync(Userid,BadgeID) then
    BadgeService:AwardBadge(Userid,BadgeID)
end
1 Like

Here is a modified version of your script:

-- // Services
local MarketPlace = game:GetService("MarketplaceService")
local BadgeService = game:GetService("BadgeService")

-- // Var
local ProductID = {
	2699503706,
	2699503784
}
local BadgeID = 4499076816490857

MarketPlace.PromptProductPurchaseFinished:Connect(function (Userid,Product_Id,Purchased)
	if Product_Id == ProductID and Purchased then
		if not BadgeService:UserHasBadgeAsync(Userid,BadgeID) then
			BadgeService:AwardBadge(Userid,BadgeID)
			print("earned donator badge!")
		end
	end
	
	if Purchased and not BadgeService:UserHasBadgeAsync(Userid,BadgeID) then
		BadgeService:AwardBadge(Userid,BadgeID)
	end
end)

Edit: Mark this as solved if it fixed your problem so other people know that this is already solved

1 Like

You should add a table for donations products so if someone buys something that is not a donations devproduct will not give the badge

1 Like

That’s what I tried to do, but it seems I don’t understand tables very well, as it didn’t work.

You have to use table.find(table, value)

1 Like

I had my doubts but this script worked because it feels redundant, but it did work. Is there anything in my original script I should remove or edit in favor of your changes? (I have no idea where the “Purchased” comes from, for starters!)

-- // Services
local MarketPlace = game:GetService("MarketplaceService")
local BadgeService = game:GetService("BadgeService")

-- // Var
local DonationsID = {
	2699503706,
	2699503784
}
local BadgeID = 4499076816490857

MarketPlace.PromptProductPurchaseFinished:Connect(function (Userid,Product_Id,Purchased)
	if table.find(DonationsID, ProductId) and Purchased then
		if not BadgeService:UserHasBadgeAsync(Userid,BadgeID) then
			BadgeService:AwardBadge(Userid,BadgeID)
			print("earned donator badge!")
		end
	end
end)
1 Like

I don’t think that script will work as there is no “ProductID”

Yes its Product_Id sorry but im on mobile

1 Like

I have tested this and it works perfectly fine, thank you so much!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.