Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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.

1 comment

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.