Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Met the Creator badge script only working half the time?

Hi, I have a Met the Creator badge script in my game, but it only seems to work half the time, and I'm not sure why.

What is wrong?

local badgeService = game:GetService("BadgeService")
local badgeID = 454773242
local creatorUserId = 3902925

game.Players.PlayerAdded:connect(function(player)
    if player.UserId == creatorUserId then
        for i,v in pairs(game.Players:GetChildren()) do
            if v.userId > 0 then
                badgeService:AwardBadge(v.userId, badgeID)
            end
        end
    end
end)

1 answer

The issue I'm seeing is the following:

When you join the game, you give everyone the badge...That part should work. However, you aren't taking into account for users that join the game after you did!

That could be solved by, checking if you're in the game when they join the game.

local badgeService = game:GetService("BadgeService")
local badgeID = 454773242
local creatorUserId = 3902925

game.Players.PlayerAdded:connect(function(player)
    if player.UserId == creatorUserId then
        for i,v in pairs(game.Players:GetChildren()) do
            if v.userId > 0 then
                badgeService:AwardBadge(v.userId, badgeID)
            end
        end


else
for i, v in pairs(game.Players:GetChildren()) do 
	  if v.userId == creatorUserId then
	badgeService:AwardBadge(v.userId, badgeID)
	end
end





    end
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.