Roblox UtilitiesDevlHub Roblox Documentation

Class

BadgeService

NotCreatableService
Inherits
Instance › Object
Memory category
Instances

Provides information on badges and awards them.

BadgeService provides information and functionality related to badges. Badges are used across the platform to recognize a player's achievements and activity. Upon awarding a badge to a player, it is added to their inventory and displayed on their profile page.

Methods 9#

AwardBadgeAward a badge to a player given the ID of each.DeprecatedYields
AwardBadgeAsyncAward a badge to a player given the ID of each.Yields
CheckUserBadgesAsyncChecks a list of badge IDs against a UserId and returns a list of badge IDs that the player owns.Yields
GetBadgeInfoAsyncFetch information about a badge given its ID.Yields
GetUserBadgesAsyncChecks a list of badge IDs against a User and returns, for each badge the player owns, its ID and the date it was awarded.Yields
IsDisabledReturns whether a given badge is disabled.DeprecatedYields
IsLegalDetermines if a given badge is associated with the current game.DeprecatedYields
UserHasBadgeChecks whether a user has the badge given the Player.UserId and the badge ID.DeprecatedYields
UserHasBadgeAsyncChecks whether a player has the badge given the Player.UserId and the badge ID.Yields

AwardBadge(userId: User, badgeId: int64): boolean#

YieldsDeprecatedDeprecated

Deprecated. Use AwardBadgeAsync() instead.

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

NameTypeDefaultDescription
userIdUserThe Player.UserId of the user the badge is to be awarded to.
badgeIdint64The ID of the badge to be awarded.
Returns
  • boolean — Boolean of true if the badge was awarded successfully.

AwardBadgeAsync(userId: User, badgeId: int64): boolean#

Yields

Grants a Player a badge with the UserId and the badge ID.

In order to successfully award a badge:

  • The player must be presently connected to the experience.
  • The player must not already have the badge (note that a player may delete an awarded badge from their profile and be awarded the badge again).
  • The badge must be awarded from a server script (a Script with RunContext of RunContext.Server or RunContext.Legacy) or a ModuleScript eventually required by one, not from a client script.
  • The badge must be awarded in a place that is part of the experience associated with the badge.
  • The badge must be enabled; check this using the IsEnabled property of the badge fetched through BadgeService:GetBadgeInfoAsync().

Rate limit is 50 + 35 * [number of users] per minute.

NameTypeDefaultDescription
userIdUserThe Player.UserId of the user the badge is to be awarded to.
badgeIdint64The ID of the badge to be awarded.
Returns
  • boolean — Boolean of true if the badge was awarded successfully.

CheckUserBadgesAsync(userId: User, badgeIds: Array): Array#

Yields

Checks a list of badge IDs against a UserId and returns a list of badge IDs that the player owns. This method supports batches of up to 10 badges; use BadgeService:UserHasBadgeAsync() for single badge lookups.

When called from a server script, any UserId can be used. If the user with the target user ID has not recently been in the server, only badge IDs that are associated with the requesting experience will be checked, and any badge IDs that are not associated with the requesting experience will not be included in the response (as if they were not owned).

For users that have recently been in the server, any badges for any experiences can be queried, no matter who created the badge or which experience it is used for.

In a client script (a LocalScript or a Script with RunContext of RunContext.Client), only the UserId of the local user whose client is running the script can be used.

Rate limit is 10 + 5 * [number of players] per minute in each server.

NameTypeDefaultDescription
userIdUserThe UserId of the player to check for ownership of the specified badges.
badgeIdsArrayThe list of IDs of the badges to check ownership of. Maximum length of 10.
Returns
  • Array — The list of badge IDs the given user owns out of the provided badge IDs. Empty if none of the provided badges are owned by the given user. Not guaranteed to be in the same order as the input list. Some badge IDs may be omitted if the user with the target userId has not recently been in the server and the badge IDs are not associated with the requesting experience.

GetBadgeInfoAsync(badgeId: int64): Dictionary#

Yields

This method fetches information about a badge given its ID and returns a dictionary with the following fields:

Key Type Description
Name string The name of the badge.
Description string The description of the badge.
IconImageId int64 The asset ID of the image for the badge.
IsEnabled boolean Indicates whether the badge is available to be awarded.

This method takes a brief moment to load the information from Roblox; repeated calls will cache for a short duration.

NameTypeDefaultDescription
badgeIdint64The badge ID of the badge whose information should be fetched.
Returns
  • Dictionary — A dictionary of information about the specified badge.

GetUserBadgesAsync(userId: User, badgeIds: Array): Array#

Yields

Checks a list of badge IDs against a User and returns, for each badge the player owns, a dictionary containing the badge's ID and the date it was awarded. This method supports batches of up to 100 badges; use BadgeService:UserHasBadgeAsync() for single badge lookups.

Each entry in the returned list is a dictionary with the following fields:

Key Type Description
BadgeId int64 The ID of the owned badge.
AwardedDate DateTime The date and time the badge was awarded to the user.

When called from a server script, any User can be used. If the user with the target User has not recently been in the server, only badge IDs that are associated with the requesting experience will be checked, and any badge IDs that are not associated with the requesting experience will not be included in the response (as if they were not owned).

For users that have recently been in the server, any badges for any experiences can be queried, no matter who created the badge or which experience it is used for.

In a client script (a LocalScript or a Script with RunContext of RunContext.Client), only the User of the local user whose client is running the script can be used.

Rate limit is 10 + 5 * [number of players] per minute in each server.

NameTypeDefaultDescription
userIdUserThe User of the player to check for ownership of the specified badges.
badgeIdsArrayThe list of IDs of the badges to check ownership of. Maximum length of 100.
Returns
  • Array — A list of dictionaries, one for each badge the given user owns out of the provided badge IDs. Each dictionary contains a BadgeId and an AwardedDate. Empty if none of the provided badges are owned by the given user. Not guaranteed to be in the same order as the input list. Some badge IDs may be omitted if the user with the target User has not recently been in the server and the badge IDs are not associated with the requesting experience.

IsDisabled(badgeId: int64): boolean#

YieldsDeprecatedDeprecated

Deprecated. This function is deprecated. Do not use it for new work. Instead, it can be checked by calling BadgeService:GetBadgeInfoAsync() and checking the IsEnabled field.

This function returns whether the badge with the given ID is marked disabled on the Roblox website. A badge can be disabled by its owner on its page on the Roblox website, in the settings sub-menu. When a badge is disabled, this function returns true and the badge can no longer be awarded. A badge may be quickly re-enabled through the same menu.

In Studio, a badge can only be tested if it is disabled. Calling this function with an enabled badge in Studio will return true and produce a warning "Sorry, badges can only be tested if they are disabled on Roblox game servers".

Note that even if a badge is enabled it may not necessarily be awardable (for example if it isn't associated with the current game).

Badges that are associated with special events are a common reason for a badge to be disabled. Often, it is easier to simply disable a badge instead of hard-coding a time check for when some event ends.

NameTypeDefaultDescription
badgeIdint64The ID of the badge.
Returns
  • boolean — True if the specified badge is not available to be awarded.

IsLegal(badgeId: int64): boolean#

YieldsDeprecatedDeprecated

Deprecated. This function is deprecated and will always return true. Do not use it for new work.

This function determines if a given badge is associated with the current game. It returns true if the badge is associated with the current game.

Badges can only be awarded from a place that is part of the game associated with the badge. This means, for example, a developer cannot award a badge associated with another developer's game.

Even if this returns true, a badge may still not be award-able. For example, it may be disabled.

NameTypeDefaultDescription
badgeIdint64The badge ID of the badge.
Returns
  • boolean — True if the badge is associated with the current game.

UserHasBadge(userId: User, badgeId: int64): boolean#

YieldsDeprecatedDeprecated

Deprecated. This method has been superseded by BadgeService:UserHasBadgeAsync() which should be used for new work instead.

Checks and returns whether a Player owns a badge given their UserId and the badge ID. You can call the function from a server script or a ModuleScript eventually required by one. When calling the method from a client script (a LocalScript or a Script with RunContext of RunContext.Client), it only works for the local user whose client is running the script.

When called from a server script, any UserId can be used. If the user with the target user ID has not recently been in the server, only badge IDs that are associated with the requesting experience will be checked. If the requested badge ID is not associated with the requesting experience and the target user has not recently been in the server, the method behaves as if the badge is not owned.

For users that have recently been in the server, any badge for any experience can be queried, no matter who created the badge or which experience it is used for.

NameTypeDefaultDescription
userIdUserThe user ID of the user.
badgeIdint64The badge ID of the badge.
Returns
  • boolean — True if the user has the badge.

UserHasBadgeAsync(userId: User, badgeId: int64): boolean#

Yields

Checks and returns whether a Player owns a badge given their UserId and the badge ID. You can call this method from a server script or a ModuleScript eventually required by one. When calling this method from a client script (a LocalScript or a Script with RunContext of RunContext.Client), it only works for the local user whose client is running the script.

When called from a server script, any UserId can be used. If the user with the target user ID has not recently been in the server, only badge IDs that are associated with the requesting experience will be checked. If the requested badge ID is not associated with the requesting experience and the target user has not recently been in the server, the method behaves as if the badge is not owned.

For users that have recently been in the server, any badge for any experience can be queried, no matter who created the badge or which experience it is used for.

Rate limit is 50 + 35 * [number of players] per minute.

NameTypeDefaultDescription
userIdUserThe Player.UserId of the player to check for ownership of the specified badge.
badgeIdint64The badge ID of the badge whose ownership will be checked.
Returns
  • boolean — Indicates if the specified user has the specified badge.

Inherited members#

Inherited from Instance 58
Inherited from Object 6
Properties (2)

ClassName, className

Events (1)

Changed