BadgeService

사용되지 않는 항목 표시

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

만들 수 없음
서비스

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

코드 샘플

다음 예제에서는 배지를 수여할 때 발생할 수 있는 잠재적 오류를 처리하는 awardBadge() 함수를 생성합니다.BadgeService:GetBadgeInfoAsync()를 통해 가져온 배지의 속성을 사용하여 배지가 수여될 수 있으며 이를 BadgeService:AwardBadge()을 사용하여 수여합니다.

배지 수여

local BadgeService = game:GetService("BadgeService")
local Players = game:GetService("Players")
local BADGE_ID = 0
local function awardBadge(player, badgeId)
-- 배지 정보 가져오기
local success, badgeInfo = pcall(function()
return BadgeService:GetBadgeInfoAsync(badgeId)
end)
if success then
-- 배지가 수여될 수 있는지 확인
if badgeInfo.IsEnabled then
-- 보상 배지
local awardSuccess, result = pcall(function()
return BadgeService:AwardBadge(player.UserId, badgeId)
end)
if not awardSuccess then
-- AwardBadge 함수가 오류를 발생시켰습니다
warn("Error while awarding badge:", result)
elseif not result then
-- AwardBadge 함수는 배지를 수여하지 않았습니다
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)

다음 스크립트는 플레이어가 게임에 들어오고 특정 배지를 소유하는지 확인하기 위해 대기합니다.이는 플레이어가 특별한 배지를 소유해야만 작동하는 충돌 필터링 또는 순간 이동 제한 영역을 만드는 데 유용합니다.

획득한 배지 확인

local BadgeService = game:GetService("BadgeService")
local Players = game:GetService("Players")
local badgeId = 00000000 -- 이를 배지 ID로 변경
local function onPlayerAdded(player)
-- 플레이어가 배지를 가지고 있는지 확인
local success, hasBadge = pcall(function()
return BadgeService:UserHasBadgeAsync(player.UserId, badgeId)
end)
-- 오류가 발생하면 경고를 발행하고 함수를 종료합니다
if not success then
warn("Error while checking if player has badge!")
return
end
if hasBadge then
-- 필요에 따라 플레이어의 배지 소유권 처리
print(player.Name, "has badge", badgeId)
end
end
-- Connect "PlayerAdded" 이벤트를 "onPlayerAdded()" 함수에 연결
Players.PlayerAdded:Connect(onPlayerAdded)

이 스크립트는 사용자가 경험에 참여할 때 소유하는 배지를 확인합니다.

일괄 처리로 획득한 배지 확인

local BadgeService = game:GetService("BadgeService")
local Players = game:GetService("Players")
local badgeIds = { 0000000000, 1111111111, 2222222222 } -- 이를 배지 ID 목록으로 변경
local function onPlayerAdded(player)
-- 플레이어에게 배지가 있는지 확인
local success, result = pcall(function()
return BadgeService:CheckUserBadgesAsync(player.UserId, badgeIds)
end)
-- 오류가 발생하면 경고를 발행하고 함수를 종료합니다
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 부울이 됩니다.

코드 샘플

다음 예제에서는 배지를 수여할 때 발생할 수 있는 잠재적 오류를 처리하는 awardBadge() 함수를 생성합니다.BadgeService:GetBadgeInfoAsync()를 통해 가져온 배지의 속성을 사용하여 배지가 수여될 수 있으며 이를 BadgeService:AwardBadge()을 사용하여 수여합니다.

배지 수여

local BadgeService = game:GetService("BadgeService")
local Players = game:GetService("Players")
local BADGE_ID = 0
local function awardBadge(player, badgeId)
-- 배지 정보 가져오기
local success, badgeInfo = pcall(function()
return BadgeService:GetBadgeInfoAsync(badgeId)
end)
if success then
-- 배지가 수여될 수 있는지 확인
if badgeInfo.IsEnabled then
-- 보상 배지
local awardSuccess, result = pcall(function()
return BadgeService:AwardBadge(player.UserId, badgeId)
end)
if not awardSuccess then
-- AwardBadge 함수가 오류를 발생시켰습니다
warn("Error while awarding badge:", result)
elseif not result then
-- AwardBadge 함수는 배지를 수여하지 않았습니다
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 목록.제공된 배지 중 하나라도 지정된 사용자가 소유하지 않은 경우 비어 있습니다.입력 목록과 동일한 순서로 보장되지 않습니다.

코드 샘플

이 스크립트는 사용자가 경험에 참여할 때 소유하는 배지를 확인합니다.

일괄 처리로 획득한 배지 확인

local BadgeService = game:GetService("BadgeService")
local Players = game:GetService("Players")
local badgeIds = { 0000000000, 1111111111, 2222222222 } -- 이를 배지 ID 목록으로 변경
local function onPlayerAdded(player)
-- 플레이어에게 배지가 있는지 확인
local success, result = pcall(function()
return BadgeService:CheckUserBadgesAsync(player.UserId, badgeIds)
end)
-- 오류가 발생하면 경고를 발행하고 함수를 종료합니다
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.

기본값: ""

반환

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

코드 샘플

다음 스크립트는 플레이어가 게임에 들어오고 특정 배지를 소유하는지 확인하기 위해 대기합니다.이는 플레이어가 특별한 배지를 소유해야만 작동하는 충돌 필터링 또는 순간 이동 제한 영역을 만드는 데 유용합니다.

획득한 배지 확인

local BadgeService = game:GetService("BadgeService")
local Players = game:GetService("Players")
local badgeId = 00000000 -- 이를 배지 ID로 변경
local function onPlayerAdded(player)
-- 플레이어가 배지를 가지고 있는지 확인
local success, hasBadge = pcall(function()
return BadgeService:UserHasBadgeAsync(player.UserId, badgeId)
end)
-- 오류가 발생하면 경고를 발행하고 함수를 종료합니다
if not success then
warn("Error while checking if player has badge!")
return
end
if hasBadge then
-- 필요에 따라 플레이어의 배지 소유권 처리
print(player.Name, "has badge", badgeId)
end
end
-- Connect "PlayerAdded" 이벤트를 "onPlayerAdded()" 함수에 연결
Players.PlayerAdded:Connect(onPlayerAdded)

이벤트