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

text chat callbacks는 비차단 콜백을 기대하므로, TextChatService.OnIncomingMessage 콜백에서 플레이어의 그룹 멤버십 상태를 쿼리하려고 하면 안 됩니다. 이렇게 하면 채팅 시스템이 멈추거나 응답하지 않을 수 있습니다.
대신, 플레이어가 서버에 입장할 때 속성을 설정하세요. 속성을 설정하면 플레이어의 상태를 재사용할 수 있어 특정 영역에 대한 접근 허용 또는 보너스 경험 제공 등의 다양한 게임의 다른 부분에서 활용할 수 있습니다.
ServerScriptService에 Script를 생성하고 다음 코드를 추가합니다:
Serverlocal Players = game:GetService("Players")-- 확인할 그룹 ID를 123456으로 변경하세요local groupID = 123456Players.PlayerAdded:Connect(function(player)local success, isInGroup = pcall(function()return player:IsInGroupAsync(groupID)end)if success and isInGroup thenplayer:SetAttribute("IsVIP", true)elseplayer:SetAttribute("IsVIP", false)endend)StarterPlayer ⟩ StarterCharacterScripts에 LocalScript를 생성하고 채팅 창에 [VIP] 태그를 표시하는 다음 코드를 추가합니다:
Clientlocal Players = game:GetService("Players")local TextChatService = game:GetService("TextChatService")TextChatService.OnIncomingMessage = function(message: TextChatMessage)local textSource = message.TextSourceif textSource thenlocal player = Players:GetPlayerByUserId(textSource.UserId)if player thenif player:GetAttribute("IsVIP") == true thenlocal overrideProperties = Instance.new("TextChatMessageProperties")overrideProperties.PrefixText = "[VIP] " .. message.PrefixTextreturn overridePropertiesendendendreturn nilend