채팅 태그 할당

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

이 예제에서는 채팅 태그를 그룹 가입에 따라 플레이어에게 할당하는 방법을 보여줍니다.채팅 태그는 채팅 창에서 플레이어를 시각적으로 식별하고 플레이어의 역할이나 상태를 나타내는 데 유용한 방법입니다.

VIP chat tag appended to user name in the chat window.

왜냐하면 텍스트 채팅 콜백은 양보할 수 없는 콜백을 기대하기 때문에, TextChatService.OnIncomingMessage 채팅 시스템이 멈추거나 반응하지 않을 수 있기 때문에 콜백에서 플레이어의 그룹 회원 상태를 쿼리하려는 것은 권장되지 않습니다.

대신, 플레이어가 서버에 참여할 때 플레이어 특성을 설정합니다.특성을 설정하면 특정 영역에 대한 액세스를 허용하거나 보너스 경험을 제공하는 등 경험의 다른 부분에서 플레이어의 상태를 재사용할 수 있습니다.

  1. Create a Script in ServerScriptService 및 다음 코드를 추가하십시오:

    서버

    local Players = game:GetService("Players")
    -- 123456를 확인하려는 그룹 ID로 바꾸기
    local groupID = 123456
    Players.PlayerAdded:Connect(function(player)
    local success, isInGroup = pcall(function()
    return player:IsInGroup(groupID)
    end)
    if success and isInGroup then
    player:SetAttribute("IsVIP", true)
    else
    player:SetAttribute("IsVIP", false)
    end
    end)
  2. 채팅 창에 [VIP] 태그를 표시하기 위해 내에 및 다음 코드를 추가하십시오:

    클라이ент

    local Players = game:GetService("Players")
    local TextChatService = game:GetService("TextChatService")
    TextChatService.OnIncomingMessage = function(message: TextChatMessage)
    local textSource = message.TextSource
    if textSource then
    local player = Players:GetPlayerByUserId(textSource.UserId)
    if player then
    if player:GetAttribute("IsVIP") == true then
    local overrideProperties = Instance.new("TextChatMessageProperties")
    overrideProperties.PrefixText = "[VIP] " .. message.PrefixText
    return overrideProperties
    end
    end
    end
    return nil
    end