PcoWSkbVqDnWTu_dm2ix
Collapse Sidebar

Chatted

The Chatted event fires when a Player types a message and presses enter in Roblox’s provided chat bar. This is done using some Lua bindings by the default chat script. You can prevent players from chatting by using StarterGui/SetCoreGuiEnabled and disabling the Chat Enum/CoreGuiType.

Chat Commands

Using this event and some string manipulation functions like string.sub and string.lower, it is possible to create chat commands, even with arguments like player names. Usually, commands are prefixed such as /heal PlayerName. To check for a prefix in a string, use string.sub on the message to check a substring of the message: string.sub(message, 1, 6) == "/heal " (note the inclusion of the space) . Then, extract the rest of the command using string.sub again: string.sub(message, 7) will be equal to the player name. Check if that player exists, and if so, perform the command’s action (in this example, healing them). Check the code samples for examples of chat commands.

Filtering

The message text fired with this event is unfiltered. If you are displaying player input like chat to other players in any form, it must be filtered using Chat/FilterStringAsync. Keep this in mind when creating your own chat systems; if your game does not properly filter chat it may have moderation action taken against it.

Parameters

Name Type Default Description

The content of the message the player typed in chat

The player that the message was intended for (nil if the player was not whispering to another player)


Code Samples


Playing/Spectating Teams

This code sample, although lengthy, is quite simple: detect when a player chats /play, then put them on the “Playing” team. When they die, move them back to the “Spectating” team.


Player.Chatted

=== Setting chatted for all players ===
There is an easy way to make the Chatted event registered on all players. Simply use the /Players/PlayerAdded event in combination with this event.


Join Team Command

This code sample allows any player to chat "/jointeam " where is the name of a team. It uses string manipulation using string.sub and string.lower to make the command case-insensitive and allow for partial matches. For example, “/jointeam red” will match the team “Red Robins”.