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

How do you make a click part to get badge?

I want to make a part where if you click it you get a badge, how can I do that?

1 comment

0

Have you created a badge?

1 answer

✓ Accepted answer

Hello there! I will answer and explain how to do that.

First, add a Script to a part and a ClickDetector. You can call the script whatever you want.

Now, open the script and get BadgeService and connect MouseClick event from ClickDetector

local BadgeService = game:GetService("BadgeService") -- Badge service, used for awarding badges
local badgeId = 1 -- Change 1 to the badge id

script.Parent.ClickDetector.MouseClick:Connect(function(Player)
       
end)

Now, we will use pcall for a protected call and we will use AwardBadge from BadgeService

local success, result = pcall(function()
		return BadgeService:AwardBadge(player.UserId, badgeId)
	end)
	if success then
		print("Success!")
	else
		warn(result) -- If it fails, used for debug
	end

Your code should look like that:

local BadgeService = game:GetService("BadgeService")
local badgeId = 1 -- Change 1 to badge id

script.Parent.ClickDetector.MouseClick:Connect(function(player)
	local success, result = pcall(function()
		return BadgeService:AwardBadge(player.UserId, badgeId)
	end)
	if success then
		print("Success!")
	else
		warn(result) -- If it fails, used for debug
	end
end)

BadgeService

3 comments

0

You should explain the code a bit more. The questioner might not understand what pcalls() are, or why you used return.

0

My bad, sorry.

0

Thank you so much! I don't have much knowledge about pcalls, but hey, I guess this is my chance to learn! :)

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