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
Using this event and some string manipulation functions like
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(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.
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.
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)
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.
=== 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