Award Badge by Owning Gamepass

Hey scripters!

I was wondering if I could get assistance, I want to write a script to detect if the player owns a gamepass, and then if they do, award them a certain badge (I’m doing this so I can add items based on the badge), but I am unable to.

My code is this:

type orlocal MarketplaceService = game:GetService("MarketplaceService")
local badgeService = game:GetService("BadgeService")
local gamepassId = 000000 -- my gamepass id
local badgeId = 000000000 -- my badge id

game.Players.PlayerAdded:Connect(function(Player)
	while wait() do
		if MarketplaceService:UserOwnsGamePassAsync(Player, gamepassId) then
			badgeService:AwardBadge(Player, badgeId)
		elseif badgeService:UserHasBadgeAsync(Player, badgeId) then
			return
		end
	end
end)
paste code here

Any ideas on what went wrong? I’ve tried using Ai to help (as the person I normally would Dm for help is away) and it, as expected, is unable to fix the problem.

local MarketplaceService = game:GetService("MarketplaceService")
local badgeService = game:GetService("BadgeService")
local gamepassId = 000000 -- put the gamepass id
local badgeId = 000000000 -- and the badge id

game.Players.PlayerAdded:Connect(function(Player)
	if MarketplaceService:UserOwnsGamePassAsync(Player.UserId, gamepassId) then -- this uses user id not an instance
		badgeService:AwardBadge(Player.UserId, badgeId) -- same here
	end
end)

Don’t use AI please. Use your own brain to figure out things and google as well. It has all the answers.

4 Likes

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