Hello, I am trying to make my own admin script, and I know that I need to use the Chatted Event, but I don't know how. I also need to use the "message" argument as the value of a variable, but I don't know how. Can you explain how to use both?
✓ ANSWER ACCEPTED
How and When to Use the Chatted Event in Admin Scripts?
1 answer
✓ Accepted answer
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.
local p = game.Players.LocalPlayer -- needs to be a localscript for this line to not be nil
p.Chatted:connect(function(message,rec)
print("Player sent " ..message.. "to" ..tostring(rec))
end)
-- you can also do:
function chat(message,rec)
print("Player sent " ..message.. "to" ..tostring(rec)) -- using tostring() stops the code from breaking if the player doesn't whisper their message, it would simply print "Player sent Hello! to", with no player.
end
p.Chatted:connect(chat)
This code would print, for example: "Player sent Hello! to Firplius".
Hope I helped!
~TDP
This discussion is preserved as it was. New answers, comments, and votes are closed.
