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.
AwardBadge will grant a player a badge given a
Player/UserId|UserId and a 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.*
- Badges must be awarded on the server, i.e. from a
ModuleScripteventually required by a
Script, instead of a
- Only Roblox game servers may award badges, i.e. badges cannot be awarded in Studio.
- The badge must be awarded in a place that is part of the game associated with the badge (checked using
- The owner of the place must also own the badge, i.e. the owner must not have deleted the badge.
- The badge must not have been disabled (checked using
A player may delete an awarded badge from their inventory and be awarded the badge again.
The ID of the badge to be awarded
True if the badge was rewarded successfully.
Awarding a Badge
This code sample includes a simple function for awarding a badge.
local BadgeService = game:GetService("BadgeService") local function awardBadge(player, badgeId) -- check badge can be awarded if BadgeService:IsLegal(badgeId) and not BadgeService:IsDisabled(badgeId) then -- award badge BadgeService:AwardBadge(player.UserId, badgeId) end end
Met the Creator Badge
The following code sample gives an example of a ‘met the creator’ badge system. This script will award a specified badge (BADGE_ID) to anyone who is in a server at the same time as the user associated with OWNER_ID.
local BadgeService = game:GetService("BadgeService") local Players = game:GetService("Players") -- change these local OWNER_ID = 212423 -- can use game.CreatorId for published places local BADGE_ID = 1 local ownerInGame = false local function playerAdded(newPlayer) if newPlayer.UserId == OWNER_ID then -- if new player is the owner, set ownerInGame to true and give everyone the badge ownerInGame = true for _, player in pairs(Players:GetPlayers()) do -- don't award the owner if player ~= newPlayer then BadgeService:AwardBadge(player.UserId, BADGE_ID) end end elseif ownerInGame then -- if the owner is in the game, award the badge BadgeService:AwardBadge(newPlayer.UserId, BADGE_ID) end end local function playerRemoving(oldPlayer) if oldPlayer.UserId == OWNER_ID then -- set ownerInGame to false ownerInGame = false end end -- listen for players joining and leaving Players.PlayerAdded:Connect(playerAdded) Players.PlayerRemoving:Connect(playerRemoving) -- fire playerAdded for existing players for _, player in pairs(Players:GetPlayers()) do playerAdded(player) end