Why does Player.Chatted event pass the chat message with "\r" appended to it?/

I have a command system using the player.Chatted event and just an hour or 2 ago, my commands stopped working and I debugged and found out that the message string has an invisible character added to the end of the string.

Code:

player.Chatted:Connect(function(message)
    print("message", message, #message)
end)

Output:

> message ! 2

So I used HttpService:JSONEncode to figure out what the invisible character was

Code:

player.Chatted:Connect(function(message)
    print("message", message, #message)
    print(HttpService:JSONEncode(message))
end)

Output:

> message ! 2
> "!\r"

The weird thing is, this does not happen on studio when playing as a solo player. It happens on live servers as well as studio’s local server feature.

I thought somehow my computer was adding \r when I press enter, but I got someone else to join and the same thing happens when he chats.

I tried testing the bug on another game and the bug still occurs.

Why is this happening?

This only started happening a few hours ago, it was working fine before then.

1 Like

This happens because you press enter to send the message which appends a carriage return. At least this is what it looks like. You can always remove it yourself by doing message = message:gsub("\r", "")

1 Like

A bug report is already filed for this, it seems like it’s because of filtering the string and to prevent spamming of new line.

1 Like