Custom text chat commands
Learn how to create custom chat commands.
TextChatService has built-in chat commands for common purposes, such as muting other players and using avatar emotes. You can enable them by setting CreateDefaultCommands to true in Studio's Properties window.
You can also add custom commands using TextChatCommand. Users sending a defined command in the chat input bar trigger a callback defined by TextChatCommand.Triggered to perform your customized actions.
The following example shows how to create a chat command that allows players to increase or decrease their character's size when they input /super or /mini.
Add a
TextChatCommandinstance insideTextChatService.Rename it to SizeCommand.
Set its
PrimaryAliasproperty to/superand itsSecondaryAliasto/mini.
Insert the following
ScriptinsideServerScriptServiceto define a callback for the chat command that scales the character's size:```lua title="Script" highlight="4,6" 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) ```