BadgeService | Documentation - Roblox Creator Hub (2024)

Show Deprecated

Not Creatable

Service

The BadgeService class provides information and functionality related tobadges. Badges are used across theplatform to recognize a player's achievements and activity. Upon awarding abadge to a player, it is added to their inventory and displayed on theirprofile page.

Code Samples

Awarding a Badge

local BadgeService = game:GetService("BadgeService")

local Players = game:GetService("Players")

local BADGE_ID = 0

local function awardBadge(player, badgeId)

-- Fetch badge information

local success, badgeInfo = pcall(function()

return BadgeService:GetBadgeInfoAsync(badgeId)

end)

if success then

-- Confirm that badge can be awarded

if badgeInfo.IsEnabled then

-- Award badge

local awardSuccess, result = pcall(function()

return BadgeService:AwardBadge(player.UserId, badgeId)

end)

if not awardSuccess then

-- the AwardBadge function threw an error

warn("Error while awarding badge:", result)

elseif not result then

-- the AwardBadge function did not award a badge

warn("Failed to award badge.")

end

end

else

warn("Error while fetching badge info: " .. badgeInfo)

end

end

local function onPlayerAdded(player)

awardBadge(player, BADGE_ID)

end

Players.PlayerAdded:Connect(onPlayerAdded)

Checking Earned Badges

local BadgeService = game:GetService("BadgeService")

local Players = game:GetService("Players")

local badgeId = 00000000 -- Change this to your badge ID

local function onPlayerAdded(player)

-- Check if the player has the badge

local success, hasBadge = pcall(function()

return BadgeService:UserHasBadgeAsync(player.UserId, badgeId)

end)

-- If there's an error, issue a warning and exit the function

if not success then

warn("Error while checking if player has badge!")

return

end

if hasBadge then

-- Handle player's badge ownership as needed

print(player.Name, "has badge", badgeId)

end

end

-- Connect "PlayerAdded" events to the "onPlayerAdded()" function

Players.PlayerAdded:Connect(onPlayerAdded)

Getting Badge Info

local BadgeService = game:GetService("BadgeService")

-- Fetch badge information

local success, result = pcall(function()

return BadgeService:GetBadgeInfoAsync(00000000) -- Change this to desired badge ID

end)

-- Output the information

if success then

print("Badge:", result.Name)

print("Enabled:", result.IsEnabled)

print("Description:", result.Description)

print("Icon:", "rbxassetid://" .. result.IconImageId)

else

warn("Error while fetching badge info:", result)

end

Summary

Properties

View all inherited from Instance

Methods

  • AwardBadge(userId : number,badgeId : number):bool

    Yields

    Award a badge to a player given the ID of each.

  • GetBadgeInfoAsync(badgeId : number):Dictionary

    Yields

    Fetch information about a badge given its ID.

  • UserHasBadgeAsync(userId : number,badgeId : number):bool

    Yields

    Checks whether a player has the badge given the Player.UserId andthe badge ID.

View all inherited from Instance

Events

View all inherited from Instance

Properties

View all inherited from Instance

Methods

AwardBadge

bool

Yields

Grants a Player a badge with the UserId andthe badge ID. Rate limit: 50 + 35 * [number of users] per minute. Inorder to successfully award a badge:

  • The player must be presently connected to the game.

  • The player must not already have the badge (note that a player maydelete an awarded badge from their profile and be awarded the badgeagain).

  • The badge must be awarded from a server-side Script or aModuleScript eventually required by a Script, not from aLocalScript.

  • The badge must be awarded in a place that is part of the game associatedwith the badge.

  • The badge must be enabled; check this using the IsEnabled property ofthe badge fetched through BadgeService:GetBadgeInfoAsync().

See also:

  • BadgeService:GetBadgeInfoAsync()

  • BadgeService:UserHasBadgeAsync()

Parameters

userId: number

The Player.UserId of the user the badge is to be awarded to.

badgeId: number

The ID of the badge to be awarded.


Returns

bool

Boolean of true if the badge was awarded successfully.

Code Samples

Awarding a Badge

local BadgeService = game:GetService("BadgeService")

local Players = game:GetService("Players")

local BADGE_ID = 0

local function awardBadge(player, badgeId)

-- Fetch badge information

local success, badgeInfo = pcall(function()

return BadgeService:GetBadgeInfoAsync(badgeId)

end)

if success then

-- Confirm that badge can be awarded

if badgeInfo.IsEnabled then

-- Award badge

local awardSuccess, result = pcall(function()

return BadgeService:AwardBadge(player.UserId, badgeId)

end)

if not awardSuccess then

-- the AwardBadge function threw an error

warn("Error while awarding badge:", result)

elseif not result then

-- the AwardBadge function did not award a badge

warn("Failed to award badge.")

end

end

else

warn("Error while fetching badge info: " .. badgeInfo)

end

end

local function onPlayerAdded(player)

awardBadge(player, BADGE_ID)

end

Players.PlayerAdded:Connect(onPlayerAdded)

GetBadgeInfoAsync

Dictionary

Yields

This function fetches information about a badge given its ID. It takes abrief moment to load the information from the Roblox website; repeatedcalls will cache for a short duration. It returns a dictionary with thefollowing fields:

KeyTypeDescription
NamestringThe name of the badge.
DescriptionstringThe description of the badge.
IconImageIdint64The asset ID of the image for the badge.
IsEnabledboolIndicates whether the badge is available to be awarded.

See also:

  • BadgeService:AwardBadge()

  • BadgeService:UserHasBadgeAsync()

Parameters

badgeId: number

The badge ID of the badge whose information should be fetched.


Returns

Dictionary

A dictionary of information about the specified badge.

Code Samples

Getting Badge Info

local BadgeService = game:GetService("BadgeService")

-- Fetch badge information

local success, result = pcall(function()

return BadgeService:GetBadgeInfoAsync(00000000) -- Change this to desired badge ID

end)

-- Output the information

if success then

print("Badge:", result.Name)

print("Enabled:", result.IsEnabled)

print("Description:", result.Description)

print("Icon:", "rbxassetid://" .. result.IconImageId)

else

warn("Error while fetching badge info:", result)

end

UserHasBadgeAsync

bool

Yields

Checks and returns whether a Player owns a badge given theirUserId and the badge ID. Rate limit: 50 + 35 *[number of players] per minute. You can call the function from theserver in a Script or ModuleScript eventually required bya Script, and the user in question must be present in the serverfor the query to run. When calling the method from the client in aLocalScript, it only works for the local user whose client isrunning the script.

Any badge for any game can be queried, no matter who created the badge orwhich experience it is used for.

See also:

  • BadgeService:GetBadgeInfoAsync()

  • BadgeService:AwardBadge()

Parameters

userId: number

The Player.UserId of the player to check for ownership of thespecified badge.

badgeId: number

The badge ID of the badge whose ownership will be checked.


Returns

bool

Indicates if the specified user has the specified badge.

Code Samples

Checking Earned Badges

local BadgeService = game:GetService("BadgeService")

local Players = game:GetService("Players")

local badgeId = 00000000 -- Change this to your badge ID

local function onPlayerAdded(player)

-- Check if the player has the badge

local success, hasBadge = pcall(function()

return BadgeService:UserHasBadgeAsync(player.UserId, badgeId)

end)

-- If there's an error, issue a warning and exit the function

if not success then

warn("Error while checking if player has badge!")

return

end

if hasBadge then

-- Handle player's badge ownership as needed

print(player.Name, "has badge", badgeId)

end

end

-- Connect "PlayerAdded" events to the "onPlayerAdded()" function

Players.PlayerAdded:Connect(onPlayerAdded)

View all inherited from Instance

Events

View all inherited from Instance

BadgeService | Documentation - Roblox Creator Hub (2024)
Top Articles
2023 Planners: 12 Best Daily Planners (Personally Reviewed!)
The best planners to keep you organized and productive in 2024
Main Moon Ilion Menu
The Pope's Exorcist Showtimes Near Cinemark Hollywood Movies 20
Cinepacks.store
Bme Flowchart Psu
12 Best Craigslist Apps for Android and iOS (2024)
Best Restaurants Ventnor
Hijab Hookup Trendy
Hca Florida Middleburg Emergency Reviews
Jc Post News
Moonshiner Tyler Wood Net Worth
Diesel Mechanic Jobs Near Me Hiring
Northern Whooping Crane Festival highlights conservation and collaboration in Fort Smith, N.W.T. | CBC News
Payment and Ticket Options | Greyhound
Xfinity Cup Race Today
The Listings Project New York
Ou Football Brainiacs
Cable Cove Whale Watching
Does Royal Honey Work For Erectile Dysfunction - SCOBES-AR
Hannah Jewell
Lininii
How often should you visit your Barber?
Vip Lounge Odu
Workboy Kennel
About | Swan Medical Group
In Branch Chase Atm Near Me
Steven Batash Md Pc Photos
Polk County Released Inmates
Reading Craigslist Pa
Edict Of Force Poe
Entry of the Globbots - 20th Century Electro​-​Synthesis, Avant Garde & Experimental Music 02;31,​07 - Volume II, by Various
Vons Credit Union Routing Number
Craigslist Com Panama City Fl
Seven Rotten Tomatoes
All-New Webkinz FAQ | WKN: Webkinz Newz
Sound Of Freedom Showtimes Near Lewisburg Cinema 8
[Teen Titans] Starfire In Heat - Chapter 1 - Umbrelloid - Teen Titans
Alba Baptista Bikini, Ethnicity, Marriage, Wedding, Father, Shower, Nazi
Wolf Of Wallstreet 123 Movies
Cvs Coit And Alpha
Take Me To The Closest Ups
Haunted Mansion Showtimes Near Millstone 14
Blippi Park Carlsbad
Craigslist Anc Ak
18 Seriously Good Camping Meals (healthy, easy, minimal prep! )
Erica Mena Net Worth Forbes
Jigidi Jigsaw Puzzles Free
Appsanywhere Mst
Chitterlings (Chitlins)
Texas 4A Baseball
Latest Posts
Article information

Author: Greg O'Connell

Last Updated:

Views: 5429

Rating: 4.1 / 5 (62 voted)

Reviews: 85% of readers found this page helpful

Author information

Name: Greg O'Connell

Birthday: 1992-01-10

Address: Suite 517 2436 Jefferey Pass, Shanitaside, UT 27519

Phone: +2614651609714

Job: Education Developer

Hobby: Cooking, Gambling, Pottery, Shooting, Baseball, Singing, Snowboarding

Introduction: My name is Greg O'Connell, I am a delightful, colorful, talented, kind, lively, modern, tender person who loves writing and wants to share my knowledge and understanding with you.