Migrating to the new TextChatService and experiencing issues

I have been getting a VERY specific problem when trying to migrate my game’s chat service to the new one.

I am using ROBLOX’s documentation and code examples to attempt to learn it, I did not make the preceding lines of code.

Serverside: (Works as intended)

Player:SetAttribute("NameColor", Color3.fromRGB(70, 70, 70))
Player:SetAttribute("ChatColor", Color3.fromRGB(70, 70, 70))
Player:SetAttribute("isYourTag", true)
Player:SetAttribute("isOtherTag", true)

Clientside: (Does not work as intended)

local PlayerService = game:GetService("Players")
local TextChatService = game:GetService("TextChatService")

TextChatService.OnChatWindowAdded = function(textChatMessage)
	local textSource = textChatMessage.TextSource
	if textSource then
		local player = PlayerService:GetPlayerByUserId(textSource.UserId)
		if player then
			local overrideProperties = TextChatService.ChatWindowConfiguration:DeriveNewMessageProperties()
			overrideProperties.PrefixText = textChatMessage.PrefixText
			overrideProperties.Text = textChatMessage.Text
			
			local nameColor = player:GetAttribute("NameColor")
			if nameColor and typeof(nameColor) == "Color3" then
				print(player, overrideProperties, overrideProperties.PrefixTextProperties, overrideProperties.PrefixTextProperties.TextColor3)
				overrideProperties.PrefixTextProperties.TextColor3 = nameColor
			end

			local chatColor = player:GetAttribute("ChatColor")
			if chatColor and typeof(chatColor) == "Color3" then
				overrideProperties.TextColor3 = chatColor
			end

			local isYourTag = player:GetAttribute("isYourTag")
			if isYourTag == true then
				overrideProperties.PrefixText = `<font color='rgb(0, 255, 0)'>[YourTag]</font> {overrideProperties.PrefixText}`
			end

			local isOtherTag = player:GetAttribute("isOtherTag")
			if isOtherTag == true then
				overrideProperties.PrefixText = `<font color='rgb(255, 0, 0)'>[OtherTag]</font> {overrideProperties.PrefixText}`
			end

			return overrideProperties
		end
	end

	return nil
end

This is the output.

Serverside, attributes are handled and are detected properly by the clientside. I can even see them when looking at the players.
Clientside, everything seems to add up. Until “overrideProperties.PrefixTextProperties” is brought into the mix. This is not a property of the TextChatService or custom settings instance created, but autofill works. overrideProperties.PrefixTextProperties.TextColor3 autofills too, but just refuses to be recognized.

This is literally copied and pasted from the documentation, therefore this should not error.
The only modifications I made were the serverside attributes and that print line clientside.
I am mortally confused.
Perhaps I have overlooked something?

1 Like

If it helps, commenting the broken line makes the chat work accordingly. Colours set up, and the default PrefixText lines work. Just not the overrideProperties.PrefixTextProperties.TextColor3 line.

Looking at the documentation, it seems that overrideProperties.PrefixTextProperties expects a ChatWindowMessageProperties instance, and is not individually assignable (at least initially).

If you create a new ChatWindowMessageProperties (say you call it prefixProps), set the colour of prefixProps like you were trying to do initially, and then and do overrideProperties.PrefixTextProperties = prefixProps, does it work?

From what I can see, it does not appear to be something you can create.
Is there a way to do that?

I will also add that the ChatWindowConfiguration appears to be unable to be duplicated, cloned, or created using scripts or the explorer panel.

image
ah, my bad. I missed this at the very top of the documentation. Let me see if I can figure something out


Edit: The return type of PrefixTextProperties is ChatWindowMessageProperties?. The question mark indicates that it may be nil. I’m not really sure what would actually cause it to be not nil though.

I would recommend encoding the style into the message text, making use of RichText instead.
e.g.

overrideProperties.PrefixText = textChatMessage.Text .. '<font color="rgb(125,125,125)">'

with </font> added somewhere else, potentially at the start of the normal text

1 Like

It worked. Thank you so much!
I’ve never touched RichText before, and it seems to be the saving grace here. Thank you!

This is the new line of code, for any of those who want a quick solution:

local name_color_override = player:GetAttribute("NameColor")
if name_color_override then
	local nameColor = name_color_override:ToHex()
	overrideProperties.PrefixText = "<font color=\"#"..nameColor.."\">"..overrideProperties.PrefixText.."</font>"
end