Badge Script Not Working

Hello, I am trying to create a script that awards a badge to people for buying at least one of a group of gamepasses.
Here is the script so far - it does not work.

local BadgeIds = {2124817966}
local PassId = {11140726,11140832,11140859,11140933,11141121,11213177,11213316,11336834,11388381,19579099}

game.Players.PlayerAdded:connect(function(p)
	if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(p.UserId, PassId) then
    	for i,Badge in pairs(BadgeIds) do
       game:GetService("BadgeService"):AwardBadge(p.UserId, Badge)
    end
  end
end)

Could you please help me with what to fix?
Thank you.

1 Like

PassId is a table, not an ID. You will need to loop through the table or directly put a single ID on the second argument.

1 Like

How do I do that? Please elaborate.

You should not ask for whole scripts. But it would be something like this:

local Players = game:GetService("Players")
local MarketplaceService = game:GetService("MarketplaceService")
local BadgeService = game:GetService("BadgeService")

local BadgeIds = {2124817966}
local PassIds = {11140726,11140832,11140859,11140933,11141121,11213177,11213316,11336834,11388381,19579099}

Players.PlayerAdded:connect(function(p)
	for i, passid in pairs(PassIds) do
		if MarketplaceService:UserOwnsGamePassAsync(p.UserId, passid) then
			for i, badgeid in pairs(BadgeIds) do
				BadgeService:AwardBadge(p.UserId, badgeid)
			end
		end
	end
end)

Use in pair Loops but I don’t think you would need a table in such a situation because there is only 1 pass.
Therefore, store the id in a variable.

Maybe he wants to make a badge that is awarded if the player buys any gamepass. But it will not be awarded until the player rejoins.

1 Like