Award Badge Script

I’m new to scripting and I’m trying to make a script that awards a player a badge when they join.

-Here’s The Script

local badge = game:GetService(“BadgeService”)
local player = game:GetService(“Players”)
player.PlayerAdded:Connect(function(player)
badge:AwardBadge(player.UserId, 2343795372069765)

end)

The error is: Argument 1 missing or nil

That seems weird.

Make sure it is:

  • A Script (not a LocalScript)
  • Located somewhere under ServerScriptService

And if that doesn’t fix it, could you show the full error code from the console?

That is because you are using the player variable twice. Do this instead:

local BadgeService = game:GetService("BadgeService")
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
    BadgeService:AwardBadge(player.UserId, 2343795372069765)
end)

Also, you should use BadgeService:UserHasBadgeAsync to make sure that it only gives you the badge if you don’t have it. Here is an updated script with it.

local BadgeService = game:GetService("BadgeService")
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
    if not BadgeService:UserHasBadgeAsync(player.UserId, 2343795372069765) then
        BadgeService:AwardBadge(player.UserId, 2343795372069765)
    end
end)
1 Like

Thanks for helping me out with this!

1 Like

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