In short
In a Script in ServerScriptService, create a TextChatCommand, set its PrimaryAlias to something like "/reset" and parent it to TextChatService. Connect to its Triggered event, which gives you the TextSource of the player who typed it and the full text. Get the Player with Players:GetPlayerByUserId(source.UserId), check on the server whether they are allowed, then run the command.
- Messages that match a command are not shown to other players, so a failed
/kickdoes not leak into chat. - Decide who is an admin on the server, by UserId or group rank. Never trust a value the client sends.
- This works with TextChatService only.
Player.Chattedand the legacy Chat service are the old way.
Get the script
Chat commands script with admin checks
One Script in ServerScriptService: /reset for everyone, and /speed, /bring, /kick and /heal for admins, checked on the server with replies in chat.
-- Script in ServerScriptService named ChatCommands.
-- /reset for everyone; /speed, /bring, /kick and /heal for admins. Admin rights are checked here, on the server.
local GroupService = game:GetService("GroupService")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TextChatService = game:GetService("TextChatService")
-- Put your admins' UserIds here, for example [123456789] = true
local ADMIN_USER_IDS: { [number]: boolean } = {
-- [123456789] = true,
}
local GROUP_ID = 0 -- your group's ID, or 0 for no group admins
local ADMIN_RANK = 200 -- group members at or above this rank are admins
local MAX_SPEED = 100
local replyEvent = ReplicatedStorage:WaitForChild("CommandReply") :: RemoteEvent
type Handler = (player: Player, args: { string }) -> ()
type CommandInfo = { alias: string, adminOnly: boolean, help: string }
local commandList: { CommandInfo } = {}
local adminCache: { [Player]: boolean } = {}
-- Sends a private line to one player's chat window (shown by the CommandReplies LocalScript)
local function reply(player: Player, text: string, isError: boolean?)
replyEvent:FireClient(player, text, isError == true)
end
local function isAdmin(player: Player): boolean
local cached = adminCache[player]
if cached ~= nil then
return cached
end
local result = ADMIN_USER_IDS[player.UserId] == true
-- The owner of a place owned by a user is always an admin
if game.CreatorType == Enum.CreatorType.User and game.CreatorId == player.UserId then
result = true
end
if not result and GROUP_ID ~= 0 then
-- GetRolesInGroupAsync asks Roblox's servers, so it can fail; a failure means no admin rights
local ok, info = pcall(function()
return GroupService:GetRolesInGroupAsync(player.UserId, GROUP_ID)
end)
-- info.Roles lists every role the player holds in the group, each with a Rank from 0 to 255
if ok and type(info) == "table" and type(info.Roles) == "table" then
for _, role in info.Roles do
if type(role) == "table" and type(role.Rank) == "number" and role.Rank >= ADMIN_RANK then
result = true
end
end
end
end
adminCache[player] = result
return result
end
-- Finds one player by the start of their name or display name, ignoring capitals. "me" is the caller.
local function findPlayer(caller: Player, query: string?): Player?
if not query then
return nil
end
local lower = string.lower(query)
if lower == "me" then
return caller
end
for _, player in Players:GetPlayers() do
local name = string.lower(player.Name)
local display = string.lower(player.DisplayName)
if string.sub(name, 1, #lower) == lower or string.sub(display, 1, #lower) == lower then
return player
end
end
return nil
end
local function addCommand(primary: string, secondary: string?, adminOnly: boolean, help: string, handler: Handler)
local command = Instance.new("TextChatCommand")
command.Name = "Custom" .. string.sub(primary, 2) .. "Command"
command.PrimaryAlias = primary
command.SecondaryAlias = secondary or ""
command.AutocompleteVisible = not adminOnly -- keep admin commands out of everyone's suggestions
command.Parent = TextChatService
table.insert(commandList, { alias = primary, adminOnly = adminOnly, help = help })
command.Triggered:Connect(function(source: TextSource, unfilteredText: string)
local player = Players:GetPlayerByUserId(source.UserId)
if not player then
return
end
if adminOnly and not isAdmin(player) then
reply(player, "You cannot use that command.", true)
return
end
-- Split the message into words and drop the first one, which is the alias
local args: { string } = {}
for word in string.gmatch(unfilteredText, "%S+") do
table.insert(args, word)
end
table.remove(args, 1)
handler(player, args)
end)
end
local function getHumanoid(player: Player): Humanoid?
local character = player.Character
return if character then character:FindFirstChildOfClass("Humanoid") else nil
end
addCommand("/reset", "/re", false, "respawn your character", function(player: Player, _args: { string })
local humanoid = getHumanoid(player)
if humanoid then
humanoid.Health = 0
end
end)
addCommand("/speed", nil, true, "/speed 32 sets your walk speed", function(player: Player, args: { string })
local speed = tonumber(args[1])
local humanoid = getHumanoid(player)
if not speed or speed ~= speed or not humanoid then
reply(player, "Use it like this: /speed 32", true)
return
end
humanoid.WalkSpeed = math.clamp(speed, 0, MAX_SPEED)
reply(player, "Walk speed set to " .. humanoid.WalkSpeed)
end)
addCommand("/bring", nil, true, "/bring name moves a player to you", function(player: Player, args: { string })
local target = findPlayer(player, args[1])
local myCharacter = player.Character
local theirCharacter = target and target.Character
if not (target and myCharacter and theirCharacter) then
reply(player, "No player found with that name.", true)
return
end
-- 4 studs in front of the admin
theirCharacter:PivotTo(myCharacter:GetPivot() * CFrame.new(0, 0, -4))
reply(player, "Brought " .. target.DisplayName)
end)
addCommand("/kick", nil, true, "/kick name removes a player", function(player: Player, args: { string })
local target = findPlayer(player, args[1])
if not target then
reply(player, "No player found with that name.", true)
return
end
if target == player or isAdmin(target) then
reply(player, "You cannot kick yourself or another admin.", true)
return
end
-- A fixed reason: text typed by one player is never shown to another without filtering
target:Kick("You were removed by an admin.")
reply(player, "Kicked " .. target.DisplayName)
end)
addCommand("/heal", nil, true, "/heal or /heal name restores full health", function(player: Player, args: { string })
local target = if args[1] then findPlayer(player, args[1]) else player
local humanoid = target and getHumanoid(target)
if not (target and humanoid) then
reply(player, "No player found with that name.", true)
return
end
humanoid.Health = humanoid.MaxHealth
reply(player, "Healed " .. target.DisplayName)
end)
addCommand("/cmds", nil, false, "lists the commands you can use", function(player: Player, _args: { string })
local admin = isAdmin(player)
for _, info in commandList do
if admin or not info.adminOnly then
reply(player, info.alias .. ": " .. info.help)
end
end
end)
Players.PlayerRemoving:Connect(function(player: Player)
adminCache[player] = nil
end)
RoCode builds it in the place you have open in Roblox Studio, on Windows or macOS with a desktop browser; on a phone the button sends the prompt and the link to your computer. Free to start, with free credits every day. More Roblox Studio scripts
Where to put it
ReplicatedStorage
CommandReply RemoteEvent new
ServerScriptService
ChatCommands Script new
StarterPlayer
StarterPlayerScripts
CommandReplies LocalScript new
Settings you can change
ADMIN_USER_IDSIn the script- The UserIds of your admins. Find a UserId in the address of a profile page on roblox.com: the number after
/users/. GROUP_IDIn the script- Your group's ID, to make group members at or above
ADMIN_RANKadmins. 0 turns group admins off. Default:0. ADMIN_RANKIn the script- The lowest group rank number (1 to 255) that counts as an admin. Default:
200.
The place owner is always an admin. The replies need the CommandReply RemoteEvent and the small LocalScript from Step 3.
What a cheater can and cannot doWho is an admin is decided only on the server, from the player's real UserId or group rank. A cheater typing /kick gets "You cannot use that command" and nothing else: why this is safe.
Type-checked with luau-lsp strict against Roblox's API definitions on 14 November 2026. Not playtested in Studio yet: press Play and watch the Output window before you publish.
Prompt for RoCode
Add chat commands to my game with TextChatService: one Script in ServerScriptService that makes TextChatCommands for /reset for everyone and admin-only /speed number, /bring name and /kick name, checks admins on the server by a list of UserIds, the place owner and a group rank, finds players by the start of their name or display name, and replies privately in the chat through a RemoteEvent and a LocalScript that uses DisplaySystemMessage.
On this page
How TextChatCommand works
A TextChatCommand is an object you put inside TextChatService. When a player sends a chat message that starts with one of its two aliases, Roblox does not show the message to anyone. It fires the command's Triggered event instead.
| Property or event | What it does |
|---|---|
PrimaryAlias | The main word, such as "/reset". Shown in the autocomplete list when you type a slash. |
SecondaryAlias | An optional second word, such as "/re". Matching ignores capital letters, and the alias must be followed by a space or the end of the message. |
AutocompleteVisible | Whether the command is suggested in the autocomplete list. It is true by default. Set it to false to hide admin commands from the list. They still work when typed in full. |
Enabled | Turn a command off without deleting it. A disabled command's text is sent as a normal chat message. |
Triggered(source, text) | Fires with the TextSource of the sender and the full, unfiltered message, alias included: "/kick Builder". |
Roblox already creates some commands, such as /e dance, /mute, /whisper and /team, in a folder named TextChatCommands inside TextChatService while the game runs (CreateDefaultCommands is ticked). Do not reuse those words for your own commands.
Step 1: Your first command, /reset
The smallest useful command: anyone can type /reset (or /re) to respawn.
- Hover over ServerScriptService, click + and insert a Script. Name it
ResetCommand. - Paste the code below, press Play and type
/resetin the chat.
-- Script in ServerScriptService named ResetCommand.
local Players = game:GetService("Players")
local TextChatService = game:GetService("TextChatService")
local resetCommand = Instance.new("TextChatCommand")
resetCommand.Name = "ResetCommand"
resetCommand.PrimaryAlias = "/reset"
resetCommand.SecondaryAlias = "/re"
resetCommand.Parent = TextChatService
resetCommand.Triggered:Connect(function(source: TextSource, _text: string)
-- The TextSource is the sender. Its UserId leads to their Player.
local player = Players:GetPlayerByUserId(source.UserId)
local character = player and player.Character
local humanoid = character and character:FindFirstChildOfClass("Humanoid")
if humanoid then
humanoid.Health = 0
end
end)
Because the Script runs on the server, the reset counts for everyone and nobody can fake it from their device. Keep this script if you only need /reset. Delete it before Step 2, which includes /reset too, or the two will both run.
Step 2: A command system with admin commands
A real game needs more than one command, so this script adds a small helper, addCommand, that creates each command, splits the text into words and checks admin rights in one place.
- Delete
ResetCommandfrom Step 1 if you made it. - Insert a RemoteEvent into ReplicatedStorage named
CommandReply. The server uses it to answer the player who typed a command. - Insert a Script into ServerScriptService named
ChatCommands, paste the code below and put your own UserId inADMIN_USER_IDS.
-- Script in ServerScriptService named ChatCommands.
-- /reset for everyone; /speed, /bring, /kick and /heal for admins. Admin rights are checked here, on the server.
local GroupService = game:GetService("GroupService")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TextChatService = game:GetService("TextChatService")
-- Put your admins' UserIds here, for example [123456789] = true
local ADMIN_USER_IDS: { [number]: boolean } = {
-- [123456789] = true,
}
local GROUP_ID = 0 -- your group's ID, or 0 for no group admins
local ADMIN_RANK = 200 -- group members at or above this rank are admins
local MAX_SPEED = 100
local replyEvent = ReplicatedStorage:WaitForChild("CommandReply") :: RemoteEvent
type Handler = (player: Player, args: { string }) -> ()
type CommandInfo = { alias: string, adminOnly: boolean, help: string }
local commandList: { CommandInfo } = {}
local adminCache: { [Player]: boolean } = {}
-- Sends a private line to one player's chat window (shown by the CommandReplies LocalScript)
local function reply(player: Player, text: string, isError: boolean?)
replyEvent:FireClient(player, text, isError == true)
end
local function isAdmin(player: Player): boolean
local cached = adminCache[player]
if cached ~= nil then
return cached
end
local result = ADMIN_USER_IDS[player.UserId] == true
-- The owner of a place owned by a user is always an admin
if game.CreatorType == Enum.CreatorType.User and game.CreatorId == player.UserId then
result = true
end
if not result and GROUP_ID ~= 0 then
-- GetRolesInGroupAsync asks Roblox's servers, so it can fail; a failure means no admin rights
local ok, info = pcall(function()
return GroupService:GetRolesInGroupAsync(player.UserId, GROUP_ID)
end)
-- info.Roles lists every role the player holds in the group, each with a Rank from 0 to 255
if ok and type(info) == "table" and type(info.Roles) == "table" then
for _, role in info.Roles do
if type(role) == "table" and type(role.Rank) == "number" and role.Rank >= ADMIN_RANK then
result = true
end
end
end
end
adminCache[player] = result
return result
end
-- Finds one player by the start of their name or display name, ignoring capitals. "me" is the caller.
local function findPlayer(caller: Player, query: string?): Player?
if not query then
return nil
end
local lower = string.lower(query)
if lower == "me" then
return caller
end
for _, player in Players:GetPlayers() do
local name = string.lower(player.Name)
local display = string.lower(player.DisplayName)
if string.sub(name, 1, #lower) == lower or string.sub(display, 1, #lower) == lower then
return player
end
end
return nil
end
local function addCommand(primary: string, secondary: string?, adminOnly: boolean, help: string, handler: Handler)
local command = Instance.new("TextChatCommand")
command.Name = "Custom" .. string.sub(primary, 2) .. "Command"
command.PrimaryAlias = primary
command.SecondaryAlias = secondary or ""
command.AutocompleteVisible = not adminOnly -- keep admin commands out of everyone's suggestions
command.Parent = TextChatService
table.insert(commandList, { alias = primary, adminOnly = adminOnly, help = help })
command.Triggered:Connect(function(source: TextSource, unfilteredText: string)
local player = Players:GetPlayerByUserId(source.UserId)
if not player then
return
end
if adminOnly and not isAdmin(player) then
reply(player, "You cannot use that command.", true)
return
end
-- Split the message into words and drop the first one, which is the alias
local args: { string } = {}
for word in string.gmatch(unfilteredText, "%S+") do
table.insert(args, word)
end
table.remove(args, 1)
handler(player, args)
end)
end
local function getHumanoid(player: Player): Humanoid?
local character = player.Character
return if character then character:FindFirstChildOfClass("Humanoid") else nil
end
addCommand("/reset", "/re", false, "respawn your character", function(player: Player, _args: { string })
local humanoid = getHumanoid(player)
if humanoid then
humanoid.Health = 0
end
end)
addCommand("/speed", nil, true, "/speed 32 sets your walk speed", function(player: Player, args: { string })
local speed = tonumber(args[1])
local humanoid = getHumanoid(player)
if not speed or speed ~= speed or not humanoid then
reply(player, "Use it like this: /speed 32", true)
return
end
humanoid.WalkSpeed = math.clamp(speed, 0, MAX_SPEED)
reply(player, "Walk speed set to " .. humanoid.WalkSpeed)
end)
addCommand("/bring", nil, true, "/bring name moves a player to you", function(player: Player, args: { string })
local target = findPlayer(player, args[1])
local myCharacter = player.Character
local theirCharacter = target and target.Character
if not (target and myCharacter and theirCharacter) then
reply(player, "No player found with that name.", true)
return
end
-- 4 studs in front of the admin
theirCharacter:PivotTo(myCharacter:GetPivot() * CFrame.new(0, 0, -4))
reply(player, "Brought " .. target.DisplayName)
end)
addCommand("/kick", nil, true, "/kick name removes a player", function(player: Player, args: { string })
local target = findPlayer(player, args[1])
if not target then
reply(player, "No player found with that name.", true)
return
end
if target == player or isAdmin(target) then
reply(player, "You cannot kick yourself or another admin.", true)
return
end
-- A fixed reason: text typed by one player is never shown to another without filtering
target:Kick("You were removed by an admin.")
reply(player, "Kicked " .. target.DisplayName)
end)
addCommand("/heal", nil, true, "/heal or /heal name restores full health", function(player: Player, args: { string })
local target = if args[1] then findPlayer(player, args[1]) else player
local humanoid = target and getHumanoid(target)
if not (target and humanoid) then
reply(player, "No player found with that name.", true)
return
end
humanoid.Health = humanoid.MaxHealth
reply(player, "Healed " .. target.DisplayName)
end)
addCommand("/cmds", nil, false, "lists the commands you can use", function(player: Player, _args: { string })
local admin = isAdmin(player)
for _, info in commandList do
if admin or not info.adminOnly then
reply(player, info.alias .. ": " .. info.help)
end
end
end)
Players.PlayerRemoving:Connect(function(player: Player)
adminCache[player] = nil
end)
Every command goes through addCommand, so the admin check cannot be forgotten on a new one. Triggered passes the full line, alias included, so string.gmatch(unfilteredText, "%S+") splits it at spaces and table.remove(args, 1) drops the alias. For /bring buil, args[1] is "buil", and findPlayer matches the first player whose name or display name starts with it.
isAdmin remembers its answer per player in adminCache, because GroupService:GetRolesInGroupAsync asks Roblox's web servers and should not run every time someone types a command. The cache is cleared when the player leaves.
Step 3: Show replies in the chat window
The server cannot write into one player's chat window directly: TextChannel:DisplaySystemMessage only works on the client. So the server sends the reply through CommandReply, and this LocalScript shows it. The message is only visible to that player.
- Open StarterPlayer, hover over StarterPlayerScripts and insert a LocalScript named
CommandReplies. - Paste the code below.
-- LocalScript in StarterPlayerScripts named CommandReplies.
-- Shows the server's replies to chat commands as system lines that only this player sees.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TextChatService = game:GetService("TextChatService")
local replyEvent = ReplicatedStorage:WaitForChild("CommandReply") :: RemoteEvent
local systemChannel = TextChatService:WaitForChild("TextChannels"):WaitForChild("RBXSystem") :: TextChannel
replyEvent.OnClientEvent:Connect(function(text: unknown, isError: unknown)
if typeof(text) ~= "string" then
return
end
-- The default RBXSystem channel colours a message red when its metadata contains "Error"
systemChannel:DisplaySystemMessage(text, if isError == true then "Error" else "Info")
end)
RBXSystem is one of the channels Roblox creates by default. It shows system messages in light grey, or red when the metadata contains the word "Error", which is why failed commands pass "Error".
Why the admin check must be on the server
It is tempting to check "is this player an admin?" in a LocalScript and hide the admin commands from everyone else. That only hides them. A cheater controls their own device, so any check that runs there can be skipped. The only check that counts is the one in Triggered on the server, which reads the real UserId Roblox attached to the message.
- Safe: the list of admin UserIds, the place owner check and the group rank check all run in ServerScriptService, which players cannot see or change.
- Safe:
/kickrefuses to kick another admin, so a stolen admin account cannot empty the server of the other admins. - Careful: anything you do with the text is your responsibility. It arrives unfiltered. Use it to find players and numbers, never to show other players a message typed by someone, unless you filter it with
TextServicefirst.
For a bigger set of tools with buttons, see the admin panel guide, which uses the same server-side check. For a list of commands players often expect, the admin commands guide covers the usual ones.
Step 4: Add your own command
Any new command is one call to addCommand. The /heal command in the script above is a good one to copy: it is admin-only, heals you when you type /heal, and heals another player when you add a name, because if args[1] then findPlayer(player, args[1]) else player picks the target.
The four arguments are the alias, an optional second alias (nil for none), whether it is admin-only, and a line of help for /cmds. The function gets the player who typed it and the words after the alias. Paste a copy of the /heal block above the /cmds one, change the alias and the help, and write what it should do. It is listed in /cmds automatically.
Step 5: Test it
- Press Play and type
/cmdsin the chat. You see every command, because in Play mode you are the place owner (if the place is owned by a group, add your UserId toADMIN_USER_IDSfirst). - Type
/speed 50: you get faster and a grey reply confirms it. Type/speed fast: a red reply explains the format. - Type
/re: your character respawns, and no one sees the message. - Open the Test tab, choose 2 players under Clients and Servers and click Start. Test players there have made-up UserIds, so neither is an admin:
/kickanswers "You cannot use that command." To test admin commands there, temporarily add[-1] = truetoADMIN_USER_IDS(the first test player is -1) and remove it again before you publish.
Common errors and fixes
If a command does nothing or shows up in chat as a normal message, check these.
The command appears in chat instead of running
Check that TextChatService.ChatVersion is TextChatService, that the command is parented to TextChatService, and that the alias includes the slash: "/reset", not "reset". A command with Enabled off is also sent as a normal message.
Infinite yield possible on CommandReply or RBXSystem
The RemoteEvent is missing from ReplicatedStorage, or the game uses the legacy chat, which has no TextChannels folder. See Infinite yield possible.
Admin commands say I cannot use them
Your UserId is not in ADMIN_USER_IDS and the place is owned by a group, so the owner check does not apply. Add your UserId, or set GROUP_ID and ADMIN_RANK.
DisplaySystemMessage errors on the server
It only works in a LocalScript (or a Script with RunContext set to Client). That is why the server sends replies through the CommandReply RemoteEvent.
Kick does not work in Studio
Kicking yourself or an admin is refused on purpose. Kick a second test player from a 2-player local server instead.
Build it with RoCode
If you would rather not set this up by hand, RoCode can build it in the place you have open. RoCode is an independent AI agent for Roblox Studio, not made by Roblox: you describe the change in a web chat, and its Studio plugin creates the parts and scripts in your Explorer, so there is no code to paste.
Add chat commands with TextChatService: /reset for everyone, and /speed, /bring, /kick and /heal only for me and rank 200+ in my group, checked on the server, with replies in chat.
- Can read your place first to see whether it uses TextChatService and what scripts already exist
- Writes the scripts with Create Script and is told to compile-check each one with Check Script
- Sets an undo point before and after each batch of changes, so Ctrl+Z steps back one batch at a time
Questions
How do I make a chat command in Roblox Studio?
Create a TextChatCommand in a server Script, set PrimaryAlias to the word with a slash, parent it to TextChatService, and connect to Triggered. Step 1 is a complete /reset command.
How do I make admin-only chat commands?
In the Triggered handler on the server, look up the Player from source.UserId and check it against a list of admin UserIds or a group rank before running the command. Step 2 does this for every admin command.
How do I get arguments from a TextChatCommand?
Triggered gives the full unfiltered text. Split it into words with string.gmatch(text, "%S+") and drop the first word, which is the alias.
Does Player.Chatted still work for commands?
It belongs to the old way of reading chat. Roblox's platform-integrated chat mode stops scripts reading what players type, and TextChatCommand is the path that still receives command text, so build new commands with it.
How do I hide a chat command from the autocomplete list?
Set AutocompleteVisible to false on the TextChatCommand. It still works when typed in full.
How do I send a message only one player sees in chat?
From a LocalScript, call DisplaySystemMessage on a TextChannel such as RBXSystem. From the server, send the text to that player with a RemoteEvent first, as Step 3 does.
Sources and further reading
- Roblox Creator Docs: TextChatCommand. aliases, AutocompleteVisible and Triggered
- Roblox Creator Docs: TextChatService. default commands and default channels
- Roblox Creator Docs: TextChannel. DisplaySystemMessage, client only
- Roblox Creator Docs: GroupService. GetRolesInGroupAsync for group rank admins
- Roblox Creator Docs: Player. Kick
How the code was checked: every script on this page passes Luau's strict type checker against Roblox's API definitions (luau-lsp, 14 November 2026). A type check catches misspelt APIs and wrong types, not game logic, so playtest in Studio before you publish.