How to check if a player sent a message or used enter in chat

I want to detect if a player sent a msg in chat and gameProcessed only works when typing but i need to check when he pressed enter and sent the message
edit: i want it in UserInputService

Use this to detect messages:

      print("player "..player.Name.." sent message: "..message)

i hope it helped you

1 Like
  • Firstly you’ll need to get the player, you can use a .PlayerAdded event for that.
  • Secondly, you need to listen for when a player sends messages using the PlayerInstance.Chatted event.
  • Thirdly, I recommend checking if there are any existing players in-game before the .PlayerAdded runs, as the players might have joined before the code began to run.

That being said, here’s an example of how you can accomplish that:

local Players = game:GetService('Players')

local function PlayerAdded(Player)
	local function Chatted(Message)
		print('Player %s has sent a message: %s'):format(Player, Message)

local GetPlayers = Players:GetPlayers()
for i = 1, #GetPlayers do
	local Player = GetPlayers[i]
		PlayerAdded(Player) -- Runs this function in parrallel for each player added before .PlayerAdded was fired.

Now, for the UserInputService: This is a client-sided service, you’ll need to use RemoteEvent:FireClient from the server script (assuming you want something done when the player chats, fire the RemoteEvent once the player chats via the server script).

RemoteEvent:FireClient(Player, Message) -- The first parameter on the OnClientEvent event will be the message.
1 Like