This function has been superseded by
BadgeService/UserHasBadgeAsync which should be used for new instead.
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.
This function returns whether a player owns a badge given the
Player/UserId|UserId and the badge’s id. Such a query can only be made under the following conditions:
- This function must be called from the server, i.e. in a
ModuleScripteventually required by a Script.
- 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. There are a number of applications of UserHasBadge:
- A restricted door that can only be opened by players who own a badge (see code sample)
- A basic way of determining if a player has played another game
- Very simple progress saving. However, it is recommended developers use
DataStoreServicefor saving as it is more scale-able and robust (remember - players can delete their own badges).
The user ID of the user.
The badge ID of the badge.
True if the user has the badge.
[Deprecated] Checking if a User Has a Badge
The below example would print “The user has this badge” if a player joined whom owned an asset with an ID of 123. If the user didn’t own an asset with an ID of 123, it would print “The user does not have this badge.”
local BadgeService = game:GetService("BadgeService") local BadgeId = 123 game:GetService("Players").PlayerAdded:Connect(function(player) if BadgeService:UserHasBadge(player.UserId, BadgeId) then print("The user has this badge") else print("The user does not have this badge") end end)