I am trying to make a "badge walk" style game, except instead of walking for a long amount of time, you just click a TextButton. However, my code doesn't work, and nothing gets written into the console.
local button = script.Parent
local BadgeService = game:GetService("BadgeService") -- this gets the service used for badges
local PlayedBadge = 2124637741 -- replace the numbers with your badge id found after you create it
local function onButtonActivated(player)
print("this should work")
-- 1
BadgeService:AwardBadge(player.UserId, PlayedBadge)
end
button.Activated:Connect(onButtonActivated)
I am using a regular script. I have followed many tutorials, but none seem to work.
Update: Because of one of the answers, I am now using this script.
local button = script.Parent
local BadgeService = game:GetService("BadgeService") -- this gets the service used for badges
local PlayedBadge = 2124637741 -- replace the numbers with your badge id found after you create it
local function onButtonActivated(player)
print("this should work")
-- 1
BadgeService:AwardBadge(player.UserId, PlayedBadge)
end
--// mouse click!
button.MouseButton1Click:Connect(onButtonActivated)
--// touch
button.TouchTap:Connect(onButtonActivated)
The TextButton works, but now I get an error:
19:15:57.265 - Players.efan343.PlayerGui.SurfaceGui.TextButton.Script:7: attempt to index nil with 'UserId'
Also, because apparently, it matters for some reason, it is a script inside a TextButton inside a SurfaceGui inside StartedGui.

2 comments
TextButton.MouseButton1Click doesn't send the player as a parameter I believe.
How do you make the player be sent?