TextChatService 內建了用於一般目的的聊天指令,例如靜音其他玩家和使用角色表情。您可以通過在 Studio 的 屬性 窗口中將 CreateDefaultCommands 設置為 true 來啟用它們。
您還可以使用 TextChatCommand 添加自訂指令。用戶在聊天輸入欄中發送定義的指令時會觸發由 TextChatCommand.Triggered 定義的回調以執行您的自訂操作。
以下示例顯示了如何創建一個聊天指令,允許玩家在輸入 /super 或 /mini 時增大或減小其角色的大小。
在 TextChatService 中添加一個 TextChatCommand 實例。
將其重新命名為 SizeCommand。

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

在 ServerScriptService 中插入以下 Script 以定義聊天指令的回調,用於調整角色的大小:
Scriptlocal TextChatService = game:GetService("TextChatService")local Players = game:GetService("Players")local sizeCommand: TextChatCommand = TextChatService:WaitForChild("SizeCommand")sizeCommand.Triggered:Connect(function(textSource, message)local scaleMult = 1local messageWords = string.split(message, " ")if messageWords[1] == "/super" thenscaleMult = 2elseif messageWords[1] == "/mini" thenscaleMult = 0.5endlocal player = Players:GetPlayerByUserId(textSource.UserId)if player thenlocal character = player.Characterif character thenlocal humanoid = character:FindFirstChildWhichIsA("Humanoid")if humanoid thenfor _, child in humanoid:GetChildren() doif child:IsA("NumberValue") thenchild.Value *= scaleMultendendendendendend)