✓ Accepted answer
Hello there! Is this a server script? If so, put the MouseButton1Down in a local script, and fire the remote event. That is my recommendation, and it may be necessary for filtering enabled.
To get the UserId of a player in a serverscript, use the PlayerAdded event. An example of it with your code is shown below:
local BadgeService = game:GetService("BadgeService")
local Players = game:GetService("Players")
game.Players.PlayerAdded:Connect(function(plr)
local UserID = plr.UserId
script.Parent.MouseButton1Down:Connect(function()
script.Parent.Parent.Click:Play()
if BadgeService:UserHasBadgeAsync(UserID, 2124620114) then
print("Giving gamepass to player")
script.LocalScript.RemoteEvent2:FireClient(plr)
end
end)
end)
The reason why this works is you define a parameter called player which is the player that has been added into the game. Therefore, you can use this parameter to access the player.
Again, I highly recommend that you change your script drastically if it is a ServerScript. I hope this helped. Have a nice day!