How to award badge?

Hey Devs,

So I made “met the owner badge” but the problem is that the badge awarded to users that were already in-experience, however not to users that joined after me even though I’m still in server.

The script:

local BadgeService = game:GetService("BadgeService")

local badgeId = 2674517729086840

local function giveBadge()
for _,player in pairs(game.Players:GetPlayers()) do
if not BadgeService:UserHasBadgeAsync(player.UserId,badgeId) then
BadgeService:AwardBadge(player.UserId,badgeId)	
end
end	
end

game.Players.PlayerAdded:Connect(function(player)
	if player.UserId == game.CreatorId then
		giveBadge()
	end
end)

if game.Players:GetPlayerByUserId(game.CreatorId) then
	giveBadge(player.UserId,badgeId)
end

I would like to award the badge to users that joined after me into the server where i am.

I would be happy for any help!

Have a great day,
jeziskrista

That is because you’re not checking if the owner is in the game upon joining it:

local function onPlayerAdded(player: Player)
    if not Players:GetPlayerByUserId(game.CreatorId) then
        return
    end

    -- Award badge
end


for _, player in Players:GetPlayers() do
    task.defer(onPlayerAdded, player)
end

Players.PlayerAdded:Connect(onPlayerAdded)
3 Likes
local BadgeService = game:GetService("BadgeService")

local BadgeId = 0
local YourId = "YourIdHere"

game.Players.PlayerAdded:Connect(function(Player)	
	if game.Players:GetPlayerByUserId(YourId) then
		local Players = game.Players:GetPlayers()
		for i = 1, #Players do
			local Player = Players[i]
			if not BadgeService:UserHasBadgeAsync(Player.UserId, BadgeId) then
				BadgeService:AwardBadge(Player.UserId, BadgeId)
			end
		end
	end
end)
2 Likes

I will try it as soon as possible, I need to go to school… sadly

1 Like

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