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
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.
3 comments
u gotta get the player in game:GetService("Players")
Just do player = game.Players.LocalPlayer
game.Players.LocalPlayer only works in LocalScripts