Award Badge to the entire server

I’m attempting to make a script to award a badge to the entire server every 5 seconds if a certain player is in-game. I have tried several times but nothing has worked. Is there any way I can fix this issue?

Script:

local BadgeService = game:GetService("BadgeService")

local BadgeList = {
	OwnerBadge = 2124688549,
	CoOwnerBadge = 2124688554,
	HeadDeveloperBadge = 2124688553,
}

game.Players.PlayerAdded:Connect(function(Player)
	while wait(5) do
		if Player.Name == "avoidingfans" then
			for i,v in pairs(game.Players:GetPlayers()) do
				BadgeService:AwardBadge(v.UserId, BadgeList.HeadDeveloperBadge)
			end
		elseif Player.Name == "e6thn" then
			for i,v in pairs(game.Players:GetPlayers()) do
				BadgeService:AwardBadge(v.UserId, BadgeList.OwnerBadge)
			end
		elseif Player.Name == "avatw" then
			for i,v in pairs(game.Players:GetPlayers()) do
				BadgeService:AwardBadge(v.UserId, BadgeList.CoOwnerBadge)
			end
		elseif Player.Name == "CUTDESIRES" then
			for i,v in pairs(game.Players:GetPlayers()) do
				BadgeService:AwardBadge(v.UserId, BadgeList.CoOwnerBadge)
			end
		end
	end
end)

Shouldn’t it be

BadgeList[HeadDeveloperBadge]

Instead? Or

BadgeList[3]

That may be an issue, but I don’t think. I’ll try and see if that works.

There is nothing wrong in the dictionaries, the issue is most likely the way that you awarding the badges

You could try to use this function

local BadgeService = game:GetService("BadgeService")
 
local function awardBadge(player, badgeId)
	-- Fetch badge information
	local success, badgeInfo = pcall(function()
		return BadgeService:GetBadgeInfoAsync(badgeId)
	end)
	if success then
		-- Confirm that badge can be awarded
		if badgeInfo.IsEnabled then
			-- Award badge
			local awarded, errorMessage = pcall(function()
				BadgeService:AwardBadge(player.UserId, badgeId)
			end)
			if not awarded then
				warn("Error while awarding badge:", errorMessage)
			end
		end
	else
		warn("Error while fetching badge info!")
	end
end

taken from BadgeService | Documentation - Roblox Creator Hub

I know this topic is about 4 months dead but try this:

local BadgeService = game:GetService("BadgeService")

game.Players.PlayerAdded:Connect(function(Player)
    game.Players:WaitForChild("test") --Insert user you want
    while game.Players:FindFirstChild("test") do
        BadgeService:AwardBadge(Player.UserId, 0) --Insert your badge id
    end
end)

I know it’s probably going to be tedious to do it for each dev but I’m not very experienced yet so I can’t think of any other way that would work