Giving Badges if Player Has Item in Backpack

I might need some help with something.

I’m trying to come up with a script that gives a badge when you have an item in your backpack. I could use a hand or an example. Could anyone assist me?

Listen for the ChildAdded event on the player’s backpack.

For a specific item:

player.Backpack.ChildAdded:Connect(function(item)

if item.Name == “Item Name” then
— Award the badge
end

end)

If it’s not a specific item remove the if function and award the badge.

local BadgeService = game:GetService("BadgeService")

local badgeId = (Your badge here)

local function checkForItem(item)
    If Item == (Your Item Here) then
        BadgeService:AwardBadge(Player, badgeId)
    else
        --Other stuff here if you want
    end
end

Player.Backpack.ChildAdded:Connect(checkForItem)