自訂文本聊天室指令

*此內容是使用 AI(Beta 測試版)翻譯,可能含有錯誤。若要以英文檢視此頁面,請按一下這裡

TextChatService 內建了用於一般目的的聊天指令,例如靜音其他玩家和使用角色表情。您可以通過在 Studio 的 屬性 窗口中將 CreateDefaultCommands 設置為 true 來啟用它們。

您還可以使用 TextChatCommand 添加自訂指令。用戶在聊天輸入欄中發送定義的指令時會觸發由 TextChatCommand.Triggered 定義的回調以執行您的自訂操作。

以下示例顯示了如何創建一個聊天指令,允許玩家在輸入 /super/mini 時增大或減小其角色的大小。

  1. TextChatService 中添加一個 TextChatCommand 實例。

  2. 將其重新命名為 SizeCommand

  3. 將其 PrimaryAlias 屬性設置為 /super,並將 SecondaryAlias 設置為 /mini

  4. ServerScriptService 中插入以下 Script 以定義聊天指令的回調,用於調整角色的大小:

    Script

    local TextChatService = game:GetService("TextChatService")
    local Players = game:GetService("Players")
    local sizeCommand: TextChatCommand = TextChatService:WaitForChild("SizeCommand")
    sizeCommand.Triggered:Connect(function(textSource, message)
    local scaleMult = 1
    local messageWords = string.split(message, " ")
    if messageWords[1] == "/super" then
    scaleMult = 2
    elseif messageWords[1] == "/mini" then
    scaleMult = 0.5
    end
    local player = Players:GetPlayerByUserId(textSource.UserId)
    if player then
    local character = player.Character
    if character then
    local humanoid = character:FindFirstChildWhichIsA("Humanoid")
    if humanoid then
    for _, child in humanoid:GetChildren() do
    if child:IsA("NumberValue") then
    child.Value *= scaleMult
    end
    end
    end
    end
    end
    end)
©2026 Roblox Corporation、Roblox、Roblox 標誌及 Powering Imagination 是我們在美國及其他國家地區的部分註冊與未註冊商標。