I want to make a part where if you click it you get a badge, how can I do that?
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)