Greetings! I’m having trouble with the joining the game badge. Here’s the code.
local BadgeService = game:GetService("BadgeService")
local BadgeId = 2124807553;
game.Players.PlayerAdded:Connect(function()
local players = game.Players:GetPlayers()
for i = 1, #players do
local player = players[i]
if not BadgeService:UserHasBadgeAsync(players.UserId, BadgeId) then
BadgeService:AwardBadge(player.UserId, BadgeId)
end
end
end)
Thanks if you can help!
1 Like
when will people realize they have to tell us what actually happens when they run the script
also the way you’re doing this seems awfully inefficient, why not just use the player variable from playeradded, that would be much easier.
I am just wondering, what do you mean by the player varible, are you talking about my players variable inside of the event? Also, for now on, I’m going to be posting whatever happens when running this script. Thanks for advice.
what you can do is you can insert a variable inside of the () in function
:Connect(function(player)
this will give you the player who just joined.
1 Like
This should work
local BadgeService = game:GetService("BadgeService")
local BadgeId = 2124807553;
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAppearanceLoaded:Connect(wait)
if not BadgeService:UserHasBadgeAsync(player.UserId, BadgeId) then
BadgeService:AwardBadge(player.UserId, BadgeId)
end
end)
Thanks for the help! I finally got the badge. Although, I modified it a bit by adding another if statement as you’ll see with the code down. Also thanks to Luigi for the help with the variable and whatnot.
local BadgeService = game:GetService("BadgeService")
local BadgeId = 2124807553;
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAppearanceLoaded:Connect(wait)
if player then
if not BadgeService:UserHasBadgeAsync(player.UserId, BadgeId) then
BadgeService:AwardBadge(player.UserId, BadgeId)
end
end
end)
Anyways, quick question. Why did player.CharacterAppearanceLoaded:Connect(wait) made the different in me getting a badge?
Just asking as I want to learn why this ended up working.
1 Like
Probably cuz i changed the script
1 Like
My bad, I got the wrong copy and paste down for the code by copying another script instead of the one I needed help with
1 Like