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

How to award a badge to the player through an item?

So I have a script that is placed in a gear inside ReplicatedStorage, when the player has it in their inventory, they should receive a badge, however, it does not work. Help please.

if (script.Parent.Parent.Parent:FindFirstChild("Humanoid")) then
    print "lol"
p = script.Parent.Parent.Parent
    if (p ~= nil) then
        print("Awarding BadgeID: " ..script.Parent.BadgeID.Value .. " to UserID: " .. p.userId)
        local b = game:GetService("BadgeService")
        b:AwardBadge(p.userId, script.Parent.BadgeID.Value)
    end
end

Thanks.

1 answer

  1. Use better variable names such as "BadgeService" instead of "b"
  2. You don't need to compare something to nil because Lua conditionals have a value called "truthy". if it's true then it's true and truthy If it's false or nil then it's false if it's anything else it's truthy
  3. Award the badge consecutively with the system that gives them the gear in the first place. (4. Player.userId is deprecated use Player.UserId)
local marketplaceService = game:GetService("MarketplaceService")
local badgeService = game:GetService("BadgeService")

--code that gives tool here
if not marketplaceService:PlayerOwnsAsset(plr, script.Parent.BadgeID.Value) then
	badgeService:AwardBadge(plr.UserId, script.Parent.BadgeID.Value)
end

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