Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How and When to Use the Chatted Event in Admin Scripts?

Asked by 8 years ago

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?

1 answer

Log in to vote
2
Answered by 8 years ago

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

Ad

Answer this question