Using the chatted event:
The Chatted
event is an event of PlayerObjects
. When they fire, it simply returns two parameters; Message (string) and Recipient (player/userdata).
Message is what the player said, and Recipient is who they sent it to (if they whispered the message), otherwise it's nil.
01 | local p = game.Players.LocalPlayer |
03 | p.Chatted:connect( function (message,rec) |
04 | print ( "Player sent " ..message.. "to" .. tostring (rec)) |
09 | function chat(message,rec) |
10 | print ( "Player sent " ..message.. "to" .. tostring (rec)) |
13 | p.Chatted:connect(chat) |
This code would print, for example: "Player sent Hello! to Firplius".
Hope I helped!
~TDP