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.
My local script which uses TextChatService, is heavily inspired by the one provided on the creator hub:
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.
2 Likes
What is that titleModule.titleColor[player.Title.Value]?
Can you show what is in that titleModule is?
2 Likes
It’s a dictionary with the title names as keys, and colors sequences as values, which are used to apply the gradient to the tag:
titleModule.titleColor = {
["Noob"] = ColorSequence.new{
ColorSequenceKeypoint.new(0, Color3.fromRGB(255, 255, 127)),
ColorSequenceKeypoint.new(1, Color3.fromRGB(255, 255, 127))
},
["Guest"] = ColorSequence.new{
ColorSequenceKeypoint.new(0, Color3.fromRGB(225, 225, 225)),
ColorSequenceKeypoint.new(1, Color3.fromRGB(225, 225, 225))
},
}
1 Like
Can you test something, just make everyone have the same color gradient and see if their tag gets removed.
1 Like
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.
1 Like
Does it always fail with people of certain usernames? I am thinking a problem with length of their name maybe?
print(player.Name)
print(properties.Text)
put it after you add the prefix, see if the message is not full when you send it.
1 Like
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.
1 Like
That’s weird, I’ll need to do some of my own testing to see.
1 Like
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.
1 Like
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
I’m thinking it’s a weird quirk of localization.
Try
print(properties.Translation)
Put it after you add the formatting.
I FIGURED IT OUT.
It is the localization.
I turned off automatic chat translation. It now shows.
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