チャットタグを割り当てる

*このコンテンツは、ベータ版のAI(人工知能)を使用して翻訳されており、エラーが含まれている可能性があります。このページを英語で表示するには、 こちら をクリックしてください。

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

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

テキストチャットコールバックは、非妥協コールバックを期待しており、TextChatService.OnIncomingMessageコールバックでプレイヤーのグループメンバーステータスをクエリーしようとすると、チャットシステムが停止するか、応答しなくなる可能性があるため、呼び出しコールバックでは、グループメンバーステータスをクエリーすることは推奨されません。

代わりに、サーバーに参加するときに プレイヤー属性 を設定します。属性を設定すると、特定のエリアへのアクセスを許可したり、ボーナスエクスペリエンスを提供したりするなど、エクスペリエンスの他の部分でプレイヤーのステータスを再使用できます。

  1. Create a ScriptServerScriptService で、次のコードを追加します:

    サーバー

    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. Create a LocalScript in StarterPlayerStarterCharacterScripts と、チャットウィンドウで [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