BadgeService

사용되지 않는 항목 표시

*이 콘텐츠는 AI(베타)를 사용해 번역되었으며, 오류가 있을 수 있습니다. 이 페이지를 영어로 보려면 여기를 클릭하세요.

만들 수 없음
서비스

The 배지서비스 class provides information and functionality related to 배지 . 배지는 플랫폼 전반에 걸쳐 플레이어의 업적과 활동을 인식하는 데 사용됩니다. 배지를 플레이어에게 수여하면 인벤토리에 추가되고 프로필 페이지에 표시됩니다.

코드 샘플

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(), it confirms that the badge can be awarded and does so using BadgeService:AwardBadge().

Awarding a Badge

local BadgeService = game:GetService("BadgeService")
local Players = game:GetService("Players")
local BADGE_ID = 0
local function awardBadge(player, badgeId)
-- Fetch badge information
local success, badgeInfo = pcall(function()
return BadgeService:GetBadgeInfoAsync(badgeId)
end)
if success then
-- Confirm that badge can be awarded
if badgeInfo.IsEnabled then
-- Award badge
local awardSuccess, result = pcall(function()
return BadgeService:AwardBadge(player.UserId, badgeId)
end)
if not awardSuccess then
-- the AwardBadge function threw an error
warn("Error while awarding badge:", result)
elseif not result then
-- the AwardBadge function did not award a badge
warn("Failed to award badge.")
end
end
else
warn("Error while fetching badge info: " .. badgeInfo)
end
end
local function onPlayerAdded(player)
awardBadge(player, BADGE_ID)
end
Players.PlayerAdded:Connect(onPlayerAdded)

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 restricted area with collision filtering or teleportation that only works if a player owns a special badge.

Checking Earned Badges

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
print(player.Name, "has badge", badgeId)
end
end
-- Connect "PlayerAdded" events to the "onPlayerAdded()" function
Players.PlayerAdded:Connect(onPlayerAdded)

This script checks which badges a user owns when they join the experience.

Checking Earned Badges in Batches

local BadgeService = game:GetService("BadgeService")
local Players = game:GetService("Players")
local badgeIds = { 0000000000, 1111111111, 2222222222 } -- Change this to a list of your badge IDs
local function onPlayerAdded(player)
-- Check if the player has any of the badges
local success, result = pcall(function()
return BadgeService:CheckUserBadgesAsync(player.UserId, badgeIds)
end)
-- If there's an error, issue a warning and exit the function
if not success then
warn("Error while checking if player", player.Name, "has badges:", result)
return
end
local ownedBadgeIds = result
if #ownedBadgeIds == 0 then
print(player.Name, "does not have any of the badges")
else
print(player.Name, "has the following badges:", table.concat(ownedBadgeIds, ", "))
end
end
Players.PlayerAdded:Connect(onPlayerAdded)

This sample prints badge information fetched via BadgeService:GetBadgeInfoAsync().

Getting Badge Info

local BadgeService = game:GetService("BadgeService")
-- Fetch badge information
local success, result = pcall(function()
return BadgeService:GetBadgeInfoAsync(00000000) -- Change this to desired badge ID
end)
-- Output the information
if success then
print("Badge:", result.Name)
print("Enabled:", result.IsEnabled)
print("Description:", result.Description)
print("Icon:", "rbxassetid://" .. result.IconImageId)
else
warn("Error while fetching badge info:", result)
end

요약

메서드

속성

메서드

AwardBadge

생성

Class.Player 에 배지를 부여하는 데 사용됩니다. 배지 이름: UserId 및 배지 ID. 최대 속도 제한: 50 + 35 * [사용자 수] 의 경우. 배지를 성공적으로 부여하려면:

  • 플레이어는 현재 게임에 연결되어 있어야 합니다.
  • 플레이어는 이미 배지를 가지고 있어서는 안 됩니다(플레이어가 프로필에서 획득한 배지를 삭제하고 다시 배지를 획득할 수 있습니다).
  • 배지는 서버 사이드의 Script 또는 ModuleScript 에서 수여해야 하며, 결국 Script 에 의해 필요로 하는 2>Class.ModuleScript2> 에서는 아닙니다.
  • 배지는 배지와 관련된 게임의 일부인 장소에서 수여해야 합니다.
  • 배지를 활성화해야 합니다. 이 작업은 IsEnabled 배지 속성을 사용하여 수행합니다.

또한 참조하십시오.

매개 변수

userId: number

이 배지를 받을 사용자의 Player.UserId입니다.

badgeId: number

보상할 배지의 ID.


반환

배지가 성공적으로 획득되었다면 true 부울.

코드 샘플

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(), it confirms that the badge can be awarded and does so using BadgeService:AwardBadge().

Awarding a Badge

local BadgeService = game:GetService("BadgeService")
local Players = game:GetService("Players")
local BADGE_ID = 0
local function awardBadge(player, badgeId)
-- Fetch badge information
local success, badgeInfo = pcall(function()
return BadgeService:GetBadgeInfoAsync(badgeId)
end)
if success then
-- Confirm that badge can be awarded
if badgeInfo.IsEnabled then
-- Award badge
local awardSuccess, result = pcall(function()
return BadgeService:AwardBadge(player.UserId, badgeId)
end)
if not awardSuccess then
-- the AwardBadge function threw an error
warn("Error while awarding badge:", result)
elseif not result then
-- the AwardBadge function did not award a badge
warn("Failed to award badge.")
end
end
else
warn("Error while fetching badge info: " .. badgeInfo)
end
end
local function onPlayerAdded(player)
awardBadge(player, BADGE_ID)
end
Players.PlayerAdded:Connect(onPlayerAdded)

CheckUserBadgesAsync

생성

나쁜 배지 ID 목록을 UserId 대 로 검사하고 플레이어가 소유한 배지 ID 목록을 반환합니다.

이 메서드는 최대 10개의 배지 집합을 지원합니다. 단일 배지 검색에 대해 BadgeService:UserHasBadgeAsync()를 사용하십시오.

요금 제한: 각 서버에서 1분당 10 + 5 * [플레이어 수] 입니다.

모든 경험에 대한 배지 세트는 쿼리할 수 있으며, 누가 배지를 만들었든 간에. 모든 UserId 는 스크립트를 실행하는 로컬 사용자의 Script 에만 사용할 수 있지만, 스크립

매개 변수

userId: number

플레이어가 지정된 배지의 소유자인지 확인하기 위한 UserId입니다.

badgeIds: Array

배지 소유자 확인을 위한 ID 목록. 최대 10개의 길이.


반환

사용자가 제공된 배지 ID로 가진 배지 목록. 제공된 배지 중 하나를 소유하지 않으면 비어 있습니다. 입력 목록과 동일한 순서로 배지를 제공하지 않습니다.

코드 샘플

This script checks which badges a user owns when they join the experience.

Checking Earned Badges in Batches

local BadgeService = game:GetService("BadgeService")
local Players = game:GetService("Players")
local badgeIds = { 0000000000, 1111111111, 2222222222 } -- Change this to a list of your badge IDs
local function onPlayerAdded(player)
-- Check if the player has any of the badges
local success, result = pcall(function()
return BadgeService:CheckUserBadgesAsync(player.UserId, badgeIds)
end)
-- If there's an error, issue a warning and exit the function
if not success then
warn("Error while checking if player", player.Name, "has badges:", result)
return
end
local ownedBadgeIds = result
if #ownedBadgeIds == 0 then
print(player.Name, "does not have any of the badges")
else
print(player.Name, "has the following badges:", table.concat(ownedBadgeIds, ", "))
end
end
Players.PlayerAdded:Connect(onPlayerAdded)

GetBadgeInfoAsync

생성

이 함수는 ID가 지정된 배지에 대한 정보를 가져옵니다. Roblox 웹 사이트에서 정보를 로드하는 데 걸리는 시간은 짧지 않습니다. 반복된 호출은 캐시되지 않습니다. 다음과 같은 필드가 포함된 사전을 반환합니다.


<tbody>
<tr>
<td><b>이름</b></td>
<td>문자열</td>
<td>배지의 이름입니다.</td>
</tr>
<tr>
<td><b>설명</b></td>
<td>문자열</td>
<td>배지의 설명.</td>
</tr>
<tr>
<td><b>아이콘 이미지 ID</b></td>
<td>int64</td>
<td>배지에 대한 이미지의 자산 ID.</td>
</tr>
<tr>
<td><b>활성화되었습니다.</b></td>
<td>부울</td>
<td>배지를 획득할 수 있는지 여부를 나타냅니다.</td>
</tr>
</tbody>
유형설명

또한 참조하십시오.

매개 변수

badgeId: number

얻어야 할 배지의 ID입니다.


반환

지정된 배지에 대한 정보의 사전입니다.

코드 샘플

This sample prints badge information fetched via BadgeService:GetBadgeInfoAsync().

Getting Badge Info

local BadgeService = game:GetService("BadgeService")
-- Fetch badge information
local success, result = pcall(function()
return BadgeService:GetBadgeInfoAsync(00000000) -- Change this to desired badge ID
end)
-- Output the information
if success then
print("Badge:", result.Name)
print("Enabled:", result.IsEnabled)
print("Description:", result.Description)
print("Icon:", "rbxassetid://" .. result.IconImageId)
else
warn("Error while fetching badge info:", result)
end

UserHasBadgeAsync

생성

클래스 플레이어가 나왔습니다. 클래스 플레이어가 나왔습니다. 클

모든 게임에 대한 배지는 누구든지 쿼리할 수 있으며, 배지를 만든 사람이나 배지를 사용하는 경험은 관계 없이 쿼리할 수 있습니다.

또한 참조하십시오.

매개 변수

userId: number

지정된 배지의 소유자를 확인하기 위한 플레이어의 Player.UserId입니다.

badgeId: number

검토할 배지의 ID입니다.


반환

지정된 사용자가 지정된 배지를 가지고 있는지 여부를 나타냅니다.

코드 샘플

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 restricted area with collision filtering or teleportation that only works if a player owns a special badge.

Checking Earned Badges

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
print(player.Name, "has badge", badgeId)
end
end
-- Connect "PlayerAdded" events to the "onPlayerAdded()" function
Players.PlayerAdded:Connect(onPlayerAdded)

이벤트