この例では、チャットタグをプレイヤーにグループへのメンバーシップに基づいて割り当てる方法を示します。グループに基づいてプレイヤーを視覚的に識別する方法であり、プレイヤーの役割やステータスを示すのに便利です。

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