I have recently added chat tags in my game, which you can buy with in-game currency.
The problem is that sometimes, both the tag AND the chat content is displayed, but the username isn’t present. This seems to happen to specific people (even after rejoining). Said people are able to see their own username in chat however.
TextChatService.OnChatWindowAdded = function(message: TextChatMessage)
local properties = chatWindowConfiguration:DeriveNewMessageProperties()
if message.TextSource then
local player = Players:GetPlayerByUserId(message.TextSource.UserId)
if player:FindFirstChild("Title") and player.Title.Value ~= "" and titleModule.titleColor[player.Title.Value] then
properties.PrefixText = "["..player.Title.Value.."]"
properties.Text = message.PrefixText .. " " .. message.Text
properties.PrefixTextProperties = chatWindowConfiguration:DeriveNewMessageProperties()
gradient.Color = titleModule.titleColor[player.Title.Value]
gradient:Clone().Parent = properties.PrefixTextProperties
end
end
return properties
end
Example where we can see users where the user name isn’t appearing, while it does for others.
I’ve already confirmed that the issue doesn’t come from the color or any specific title, as sometimes the same title will display the username on one player, but not on the other. Also just to clear up anything it’s not the tag that disappears, but their username.
Doesn’t seem related to the length of their username either.
If you look in these two screenshots, the display name “FIMOZ” is shorter than “Roblox_1”, however the first one doesn’t appear while the second does.
As you can see here, I printed the value properties.Text in the console, and the username is displayed correctly. However, it disappears in the chat.
Another point to note is that text is automatically translated when appearing in the chat, so the value isn’t directly the one that will be displayed. So something may happen at that time that would cause specific usernames to disappear.
So that means your script is working the way you expect.
What I realized is that normally the username of the speaker is in the prefix text while the actual text content is in the message.Text, but this method makes it so that the username is also in the message.Text
Yeah you’re correct, I realised this as well.
After turning off automatic chat translation, the user names appear again.
I believe the following lines of codes have fixed the issue:
if message.Translation ~= "" then
properties.Translation = message.PrefixText .. " " .. message.Translation
end