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

テキストチャットコールバックは、非妥協コールバックを期待しており、TextChatService.OnIncomingMessageコールバックでプレイヤーのグループメンバーステータスをクエリーしようとすると、チャットシステムが停止するか、応答しなくなる可能性があるため、呼び出しコールバックでは、グループメンバーステータスをクエリーすることは推奨されません。
代わりに、サーバーに参加するときに プレイヤー属性 を設定します。属性を設定すると、特定のエリアへのアクセスを許可したり、ボーナスエクスペリエンスを提供したりするなど、エクスペリエンスの他の部分でプレイヤーのステータスを再使用できます。
Create a Script 在 ServerScriptService で、次のコードを追加します:
サーバーlocal Players = game:GetService("Players")-- 123456 をチェックしたいグループ ID で置換local groupID = 123456Players.PlayerAdded:Connect(function(player)local success, isInGroup = pcall(function()return player:IsInGroup(groupID)end)if success and isInGroup thenplayer:SetAttribute("IsVIP", true)elseplayer:SetAttribute("IsVIP", false)endend)Create a LocalScript in StarterPlayer ⟩ StarterCharacterScripts と、チャットウィンドウで [VIP] タグを表示するための次のコードを追加します:
クライバーlocal 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