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"}
game.Players.PlayerAdded:Connect(function(plr)
plr.Chatted:connect(function(msg)
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)
end
end
end
end
end)
end)
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.
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.
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: