Does anyone have a badge awarder script?

I am trying to make a badge when you touch it you get a badge.

I have tried to do it but it dosent work, could anyone help?

You could do something like this:

local BadgeService = game:GetService("BadgeService")
local badgeID = 319283391293

part.Touched:Connect(function(object)
	local player = game.Players:GetPlayerFromCharacter(object.Parent)
	
	if player then
		local success, errorMessage = pcall(function()
			BadgeService:AwardBadge(player.UserId, badgeID)
		end)
		
		if not success then
			-- THis code will run if the badge awarding failed maybe tell the player to touch the part again.
		end
	end
end)

Just replace part with whatever part you want

EDIT: just updated the script to include a pcall around the AwardBage function in case it fails

2 Likes

I will try it out, thanks you, I hope it works!

1 Like

For some reason badges in my game dosent work, when I try multiple ways that worked before it dosent work, do you know what the problem is?

1 Like

Is nothing at all happening or is there an error in the output?

2 Likes

I have no idea, do you think you could help me in studio?

1 Like

Lets move this to DMs. I will DM you.

1 Like

Please remember to post the problem and solution once you’ve found it. Everyone has the experience of looking through a thread about their problem only for it to end like that. Best not increment people’s counts. Thanks for providing help, though!

1 Like

Oh sorry completely forgot it was in fact the solution above.