Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

UserId is not a valid member of Players "Players" ?

Asked by 2 years ago

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;

while wait() do
if game.Workspace.CongratsBadge.Value==true then
local badgeID = [MyBadgeID]
local badgeService = game:GetService("BadgeService")
for _,v in pairs(game.Players:GetPlayers()) do
    if not badgeService:UserHasBadge(game.Players.UserId, badgeID) then
        badgeService:AwardBadge(game.Players.UserId, badgeID)
    end
    end
end

1 answer

Log in to vote
1
Answered by 2 years ago

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.


for i, player in pairs(game.Players:GetPlayers()) do -- the player is the actual player, so you could rewrite your code like this: if not badgeService:UserHasBadge(player.UserId, badgeID) then badgeService:AwardBadge(game.Players.UserId, badgeID) end end

I have not tested this nor do I have any experience with badge service, but I think this should work.

0
Thank you so much, it worked. I can't still believe I just missed the fact that "v" is a value that I'm Indexing, lol. Thanks again. Va1t_Dev 86 — 2y
Ad

Answer this question