Test it out to see if it works, since I can’t do that for you (I can’t award a badge that isn’t mine). It should work though
I tried it is studio and in-game, still does not work
And you’ve made completely sure you don’t own the badge (and there’s no errors)?
Yes, I do not own it and there are no errors in the dev board
It should be noted that this will only work if the username you put in is already in the game by the time the badge earner joins. Also, you might want to try using your userid instead of a username (v.UserId == exampleId
). Other than that, I’m not sure. It should work just fine. Try using a print right before awarding the badge to see if it gets to there.
local BadgeService = game:GetService("BadgeService")
local function awardBadge(plr, badgeId)
local success, badgeInfo = pcall(BadgeService.GetBadgeInfoAsync, BadgeService, badgeId)
if success then
if badgeInfo.IsEnabled then
local awarded, errorMessage = pcall(BadgeService.AwardBadge, BadgeService, plr.UserId, badgeId)
end
end
end
game.Players.PlayerAdded:Connect(function(plr)
for _,v in pairs(game.Players:GetPlayers()) do
if v.UserId == 3161482243 then
awardBadge(plr, 2128736008)
end
end
end)
Yes, that should work as long as that’s the correct UserId. Since it isn’t, however, I’d recommend adding print statements in the awardBadge function to figure out where it stops (or rather if it starts at all).
game.Players.PlayerAdded:Connect(function(plr)
for _,v in pairs(game.Players:GetPlayers()) do
if v.UserId == 3161482243 then
printawardBadge(plr, 2128736008)
end
end
end)
What I meant was this:
local BadgeService = game:GetService("BadgeService")
local function awardBadge(plr, badgeId)
print("Started")
local success, badgeInfo = pcall(BadgeService.GetBadgeInfoAsync, BadgeService, badgeId)
if success then
print("collected badge info")
if badgeInfo.IsEnabled then
print("trying to award")
local awarded, errorMessage = pcall(BadgeService.AwardBadge, BadgeService, plr.UserId, badgeId)
end
end
end
Using that, you can see where it got to before stopping (or if it started)
So delete the script and put this in it?
No, just replace the function with that.
local BadgeService = game:GetService("BadgeService")
local function awardBadge(plr, badgeId)
print("Started")
local success, badgeInfo = pcall(BadgeService.GetBadgeInfoAsync, BadgeService, badgeId)
if success then
print("collected badge info")
if badgeInfo.IsEnabled then
print("trying to award")
local awarded, errorMessage = pcall(BadgeService.AwardBadge, BadgeService, plr.UserId, badgeId)
end
end
end
game.Players.PlayerAdded:Connect(function(plr)
for _,v in pairs(game.Players:GetPlayers()) do
if v.UserId == 3161482243 then
printawardBadge(plr, 2128736008)
end
end
end)
Yes. Unless I say otherwise, you can just do what I say and then test it. You don’t have to show me every time you change it
I’m just not good at scripting sorry, my title is game designer for a reason lol
You still have it as printawardBadge
which doesn’t exist. Replace it with awardBadge
Sure enough, it is trying to give the player the badge. There probably isn’t issue with your code, it’s making it to the part where it gives it to them. Try replacing it with this and tell me what it says:
local BadgeService = game:GetService("BadgeService")
local function awardBadge(plr, badgeId)
local success, badgeInfo = pcall(BadgeService.GetBadgeInfoAsync, BadgeService, badgeId)
if success then
if badgeInfo.IsEnabled then
local awarded, errorMessage = pcall(BadgeService.AwardBadge, BadgeService, plr.UserId, badgeId)
print(awarded,errorMessage)
end
end
end
game.Players.PlayerAdded:Connect(function(plr)
for _,v in pairs(game.Players:GetPlayers()) do
if v.UserId == 3161482243 then
awardBadge(plr, 2128736008)
end
end
end)
According to this, it successfully awarded the badge. There shouldn’t be anything wrong, it doesn’t notify you if you already own the badge (which you likely do, since it’s been working and we just figured that out)