Award player a badge with chat?

I’m trying to make it possible for myself to give players a badge using a chat command. Here is what I have so far:

local Admins = {"catostomus"}
  for i, AdminPerson in ipairs(Admins) do
   if plr.Name == AdminPerson then
    if msg:sub(1, 7) == "/award " then
     local PlayerToBeAwarded = game.Players:FindFirstChild(msg:sub(8))
     if PlayerToBeAwarded then
    game:GetService("BadgeService"):AwardBadge(plr.UserID, 2124505078)

Unsure what the problem is.


Anything in the out put?

On another note, I would use :Connect instead of :connect, just makes it easier.

1 Like

No nothing of interest. I have never used BadgeService before, am I doing it correctly?

I think the problem is this line. You’re using plr, which is the admin that joined, not the player awarded in the chat. To fix this, just put PlayerToBeAwarded.UserId instead of plr.UserId.

game:GetService("BadgeService"):AwardBadge(PlayerToBeAwarded.UserId, 2124505078)

I gave that a try, still no luck. I also noticed I was using UserID and not UserId, but this didn’t seem to fix it either.

How, exactly, are you testing this?
If you are testing this in studio, I would test it in a proper game. I’ll join you to help.

1 Like

I’m testing it in the actual game using an alt (the alt has permission to run the command).

You may want to insert a UserOwnsBadge function:

BadgeService:UserHasBadgeAsync(PlayerToBeAwarded.UserId, badgeID)

Also, here is the API reference for BadgeService.

1 Like

Still nothing sadly, I’ll try to see if I can come up with something to solve it. Worst case I ask a mutual who has more knowledge than I do.

Is your badge enabled? Is your script a server script?

I would check to find the badge, using this:

1 Like

As far as I can tell its enabled, it works when awarding the badge in other ways. image

 game:GetService("BadgeService"):AwardBadge(plr.UserID, 2124505078)

You are attempting to award the badge to the admin who casts the command, try replacing it with this and see if it works:

 game:GetService("BadgeService"):AwardBadge(PlayerToBeAwarded.UserID, 2124505078)

Already attempted this, no luck with it for some reason.

Make sure you have the correct badge ID.
Perhaps define BadgeService before hand.
Make sure to spell check your work.

1 Like

Oh! I tried this again just for the sake of it, for some reason it seems to be working now? Thank you all very much for helping me and taking the time out of your day replying.


Glad I could help!

One last contribution, you’re looping through the table to check if the player is an admin but you’re never breaking that loop so it is using up memory, I recommend replacing that loop with this if/then statement:

if table.find(Admins,plr.Name) then