Hello!
If you fill the Chat Bar in a new TextChatService chat with multibyte symbols (cyrillic or arabic are the best example) or symbols such as § - you will receive an error message saying, “Your message exceeds the maximum message length,” which is not true.
This does happen both in Studio and in real experiences.
This does not happen in a LegacyChatService
This started happening since the release of a new TextChatService chat.
This happens 100% of the time for all of the players who wrote long text only including such symbols.
The possible reason for this issue is incorrect character counting. Most likely, the chat is checking the character count using the method string.len(string)
or #string
, which is incorrect because these methods count multiple characters for multibyte symbols. The correct method to use is utf8.len(string)
, which accurately counts the number of characters visible in the string.
To support my theory, I’ve created a 3-line script, as shown below (including screenshots from the studio):
local string_LATIN, string_CYRILLIC = "PRIVET","ПРИВЕТ" -- 6 characters visible in both
print(string.len(string_LATIN), string.len(string_CYRILLIC), " -- string.len() Method\n")
print(utf8.len(string_LATIN), utf8.len(string_CYRILLIC), " -- utf8.len() Method\n")
-- string.len() method returns(6,12) - the results are different because CYRILLIC symbols are multibyte
-- utf8.len() method returns (6,6) - correct result
Output in Studio: