How can I add square brackets in the chat to the players name?

Hi, I am currently using TextChatService to apply chat tags, and that works fine, but when i want to add square brackets…

properties.PrefixText = table.concat(prefixes, " ") .. " " .. message.PrefixText
properties.PrefixText = string.gsub(properties.PrefixText, player.DisplayName, "[" .. player.Name .. "]")

the chat turns white and breaks:
image

However this piece of code…

properties.PrefixText = table.concat(prefixes, " ") .. " " .. message.PrefixText
properties.PrefixText = string.gsub(properties.PrefixText, player.DisplayName, player.Name)

works as normal:
image

So i was wondering how I could fix this? Any help would be appreciated, thanks!

1 Like

Does it do this with any other characters? Try ( ) or putting just a letter before and after. Im thinking its a rich text escape issue, but I need you to try those to know.

1 Like

if it were an issue with RichText, they should try escaping it with a backslash(\), although I don’t recall brackets([]) being used in string formatting

1 Like

when showing the second piece of code it seems like it already has square brackets. am i missing something?

1 Like

no i mean the players name and not the chat tag

brackets seem to work in studio…
image

but not in game?

it seems to do it with every character i tried (brackets, stars, dashes etc)

I have no idea what could be causing this then, sorry.

maybe its not the best to use table.concat in here

2 Likes