BadgeService

사용되지 않는 항목 표시

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

만들 수 없음
서비스

배지 서비스 클래스는 배지와 관련된 정보와 기능을 제공합니다.배지는 플랫폼 전체에서 플레이어의 업적과 활동을 인식하는 데 사용됩니다.플레이어에게 배지를 수여하면 인벤토리에 추가되고 프로필 페이지에 표시됩니다.

코드 샘플

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

생성

와 배지 ID를 가진 배지를 부여합니다.Grants a badge with the and the badge ID.속도 제한: 분당 50 + 35 * [사용자 수] .배지를 성공적으로 수여하려면:

  • 플레이어는 현재 게임에 연결되어 있어야 합니다.
  • 플레이어는 이미 배지를 가지고 있지 않아야 합니다(플레이어가 수여받은 배지를 프로필에서 삭제하고 다시 배지를 수여받을 수 있음을 참고).
  • 배지는 서버 측 또는 서버 측에서 마침내 요구하는 에서 수여해야 하며, 에서 요구하는 것이 아닙니다.
  • 배지는 배지와 관련된 게임의 일부인 장소에서 수여해야 합니다.
  • 배지가 활성화되어야 합니다; 배지가 가져온 속성 을 사용하여 이것을 확인하십시오.

참조하세요:

매개 변수

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()를 사용하십시오.

속도 제한: 분당 10 + 5 * [플레이어 수] 각 서버에서 모든 서버에서.

누가 배지를 만들었거나 배지가 어떤 경험에 속하든 상관없이 모든 경험에 대한 배지 세트를 쿼리할 수 있습니다.모든 UserIdScript 에서 사용할 수 있지만, LocalScript 에서는 클라이언트가 스크립트를 실행하는 로컬 사용자의 UserId 만 사용할 수 있습니다.

매개 변수

userId: number

지정된 배지의 소유권을 확인하기 위한 플레이어의 UserId .

기본값: ""
badgeIds: Array

소유권을 확인할 배지의 ID 목록. 최대 길이는 10입니다.

기본값: ""

반환

지정된 사용자가 제공된 배지 ID 중에서 소유하는 배지 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 웹사이트에서 정보를 로드하는 데는 짧은 시간이 걸리지만, 반복된 호출은 짧은 기간 동안 캐시됩니다.다음 필드로 사전을 반환합니다:


<th>유형</th>
<th>설명</th>
</tr>
</thead>
<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>사용 가능 IsEnabled</b></td>
<td>부울</td>
<td>배지를 수여할 수 있는지 여부를 나타냅니다.</td>
</tr>
</tbody>

참조하세요:

매개 변수

badgeId: number

검색할 정보가 있는 배지의 배지 ID입니다. The badge ID of the badge whose information should be fetched.

기본값: ""

반환

지정된 배지에 대한 정보 사전.

코드 샘플

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

생성

검사하고 반환하여 배지를 소유하고 있는지 및 배지 ID가 무엇인지 여부를 확인합니다.속도 제한: 분당 50 + 35 * [플레이어 수] .서버에서 함수를 호출할 수 있으며 또는 결국 필요한 서버에서 요구되는 사용자가 서버에 존재해야 쿼리가 실행됩니다.클라이언트에서 메서드를 호출할 때, LocalScript 에서 로컬 사용자의 클라이언트가 스크립트를 실행하는 경우에만 작동합니다.

누가 배지를 만들었는지나 배지가 어떤 경험에 사용되는지에 상관없이 모든 게임에 대한 배지를 쿼리할 수 있습니다.

참조하세요:

매개 변수

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)

이벤트