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

(answered) UserId is not a valid member of Players?

This error has been annoying me over 2019 anyone knows how to fix it? heres the script.

script.Parent.MouseButton1Click:Connect(function() local BadgeID = "10101" local player = game:GetService("Players") if game:GetService("BadgeService"):UserHasBadgeAsync(player.UserId, BadgeID) then print("lol") else print("ha") end end)

im trying to make a badge checker gui

3 comments

0

u gotta get the player in game:GetService("Players")

0

Just do player = game.Players.LocalPlayer

0

game.Players.LocalPlayer only works in LocalScripts

1 answer

script.Parent.MouseButton1Click:Connect(function()
     local BadgeID = "10101"
     local player = game:GetService("Players")
     if game:GetService("BadgeService"):UserHasBadgeAsync(player.UserId, BadgeID) then. 
          print("lol")
     else 
          print("ha") 
     end
end)

Your error is on line 3. This is finding the players not the player. To find the player, you would use script.Parent and keep adding .Parents until you are talking about the ScreenGui (I know it is a ScreenGui because only Image/TextButtons use MouseButton1Click). That is when you add .Parent.Parent. This looks for the ScreenGui, which, when the player can see it, goes in the player's PlayerGui; after finding the PlayerGui, the Player is the PlayerGui's parent.

Example: script > button > frame > ScreenGui

script.Parent.MouseButton1Click:Connect(function()
     local player = script.Parent.Parent.Parent.Parent.Parent --script > button > frame > ScreenGui > PlayerGui > Player
end)

You also have 1 more error that is less critical: on line 2, you are setting local BadgeID to a string value not a number.

I hope this solves your problem.

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