How would i award a badge in this case?

I Have a script that allows a player to pick up a item, and place it on a NPC.

I would like this script to award a badge to the player but i have been unsuccessful.

Here is the script


local p = game:GetService("Players")

local SnakeSaber = script.Parent

local IV = script.Parent.ValkyrieHelm.Handle


SnakeSaber.Torso.Touched:Connect(function(hit)
	if hit.Name == "Ice Valkyrie" then
		IV.Transparency = 0

		hit:Destroy()

		
	end
end)```

any help would be appreciated!
1 Like

Badges | Documentation - Roblox Creator Hub Dev hub article

     Sample script

      ''''

           local BadgeService = game:GetService("BadgeService")

           local function awardBadge(player, badgeId)

           local success, badgeInfo = pcall(function()
	         return BadgeService:GetBadgeInfoAsync(badgeId)
           end)
           if success then
	          if badgeInfo.IsEnabled then
		-- Award badge
		local awarded, errorMessage = pcall(function()
			BadgeService:AwardBadge(player.UserId, badgeId)
		end)
		if not awarded then
			warn("Error while awarding badge:", errorMessage)
		end
	end
else
	warn("Error while fetching badge info!")
end
end

                 '''

You poorly copy pasted a script from the Wiki, please don’t spoonfeed (incorrect in this case) scripts, you could’ve simply linked the documenation of the method responsible for giving awards instead.

The script is just how you would award the badge, @OP can figure out the rest

Well, I don’t know how you handle when you place it on a NPC. Touched event is not really a go way. Instead, you can check the magnitude.

For detecting if it was placed, you can add a StringValue with the Player’s name as it’s value. You would then find a player in the Players service then you would aware the badge.

Might not be the best solution, but yeah. That’s what I could think.