チャットタグの割り当て

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

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

チャットウィンドウにユーザー名に追加されたVIPチャットタグ。

text chat callbacksは非待機のコールバックを期待しているため、TextChatService.OnIncomingMessageコールバック内でプレイヤーのグループメンバーシップの状態をクエリしようとすることは推奨されません。これはチャットシステムがハングするか、応答しなくなる可能性があります。

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

  1. ServerScriptServiceScriptを作成し、次のコードを追加します。

    Server

    local Players = game:GetService("Players")
    -- チェックしたいグループIDを123456で置き換えます
    local groupID = 123456
    Players.PlayerAdded:Connect(function(player)
    local success, isInGroup = pcall(function()
    return player:IsInGroupAsync(groupID)
    end)
    if success and isInGroup then
    player:SetAttribute("IsVIP", true)
    else
    player:SetAttribute("IsVIP", false)
    end
    end)
  2. StarterPlayerStarterCharacterScriptsLocalScriptを作成し、チャットウィンドウに**[VIP]**タグを表示するための次のコードを追加します。

    Client

    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
©2026 Roblox Corporation。Roblox(ロブロックス)、RobloxロゴおよびPowering Imaginationは、米国並びにその他の国における登録商標および非登録商標です。