AwardBadge
This is a yielding function. When called, it will pause the Lua thread that called the function until a result is ready to be returned, without interrupting other scripts.
For thread safety, this property is not safe to read in an unsynchronized thread.
AwardBadge grants a Player a articles/Badges Special Game Awards|badge given the player’s Player/UserId|UserId and the badge ID. In order to successfully award a badge, the following criteria must be met:
- The player must be presently connected to the game.
- 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-side
Scriptor aModuleScripteventually required by aScript, not from aLocalScript. - The badge must be awarded in a place that is part of the game associated with the badge.
- The owner of the place must also own the badge (for example, the owner must not have deleted the badge).
- The badge must be enabled; check this using the
IsEnabledproperty of the badge fetched viaBadgeService/GetBadgeInfoAsync|BadgeService:GetBadgeInfoAsync().
See also
BadgeService/GetBadgeInfoAsync|BadgeService:GetBadgeInfoAsync()BadgeService/UserHasBadgeAsync|BadgeService:UserHasBadgeAsync()
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
|
|
The |
||
|
|
The ID of the badge to be awarded. |
Returns
| Return Type | Summary |
|---|---|
|
Boolean of |
Code Samples
Awarding a Badge
The following example creates an awardBadge() function that handles potential errors that may occur when awarding a badge. Using properties of the badge fetched via BadgeService/GetBadgeInfoAsync|BadgeService:GetBadgeInfoAsync(), it confirms that the badge can be awarded and does so using BadgeService/AwardBadge|BadgeService:AwardBadge().