Hello there,
So I'm trying to make a script that awards player a badge when a bool value is "true". I know UserID is not a valid member of "Players" thing, but I'm a noob at scripting and I have no idea what to put instead. What should I do now? Here's the script;
01 | while wait() do |
02 | if game.Workspace.CongratsBadge.Value = = true then |
03 | local badgeID = [ MyBadgeID ] |
04 | local badgeService = game:GetService( "BadgeService" ) |
05 | for _,v in pairs (game.Players:GetPlayers()) do |
06 | if not badgeService:UserHasBadge(game.Players.UserId, badgeID) then |
07 | badgeService:AwardBadge(game.Players.UserId, badgeID) |
08 | end |
09 | end |
10 | end |
So when using for in pairs, the 'v' is the value you are indexing. So in this case, you could rewrite the code like this to make it easier.
1 | for i, player in pairs (game.Players:GetPlayers()) do |
2 | -- the player is the actual player, so you could rewrite your code like this: |
3 | if not badgeService:UserHasBadge(player.UserId, badgeID) then |
4 | badgeService:AwardBadge(game.Players.UserId, badgeID) |
5 | end |
6 | end |
I have not tested this nor do I have any experience with badge service, but I think this should work.