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.
Checks whether a
Player owns a
articles/Badges Special Game Awards|badge given their
Player/UserId|UserId and the badge ID. This query can only be made under the following conditions:
- This function must be called from a server-side
ModuleScripteventually required by a
Script, not from a
- The player in question must be present in the server.
Any badge for any game can be queried, no matter who created the badge or which game it is used for.
The badge ID of the badge whose ownership will be checked.
A boolean indicating if the specified user has the specified badge.
Checking Earned Badges
The following script waits for any player to enter the game and checks if they own a specific badge. This is useful for creating a
articles/Collision Filtering Team Doors|restricted area or
articles/Teleporting Between Places|teleporter that only works if a player owns a special badge.
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 end end -- Connect "PlayerAdded" events to the "onPlayerAdded()" function Players.PlayerAdded:Connect(onPlayerAdded)