Unable to Seperate Chat Text Color from Bubble Text

In our game we modify chat message color to a yellow color for specific users, however this also changes the text bubble color. Maybe we’re not doing text color correctly, however this is ugly and it should be possible to have different colors for them both.

Associated Code

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

TextChatService.OnIncomingMessage = function(Message)
	if Message.TextSource then
		local OriginalText = Message.Text
		local OriginatingPlayer = Players:GetPlayerByUserId(Message.TextSource.UserId)
		local PrefixText = OriginatingPlayer:GetAttribute('PrefixText')
		local ChatColor = OriginatingPlayer:GetAttribute('ChatColor')
		
		require(game.ReplicatedStorage:WaitForChild('LocalChatTranslator')).Translate(Message)
		
		if Message.Text ~= OriginalText then -- don't want to mis-translate command texts
			Message.Translation = Message.Text
		end
		
		if PrefixText then
			local properties = Instance.new("TextChatMessageProperties")
			properties.PrefixText = PrefixText..Message.PrefixText
			
			if ChatColor then
				properties.Text = '<font color="rgb('..math.floor(ChatColor.R*255)..', '..math.floor(ChatColor.G*255)..', '..math.floor(ChatColor.B*255)..')">'..Message.Text..'</font>'
				properties.Translation = '<font color="rgb('..math.floor(ChatColor.R*255)..', '..math.floor(ChatColor.G*255)..', '..math.floor(ChatColor.B*255)..')">'..Message.Translation..'</font>'
			end

			return properties
		end
	elseif Message.Metadata == "Roblox.ChatTranslation.ChatWindow.SystemMessage" then -- bue bye switch team text
		Message.Text = ""
	end
end

local Chat = game:GetService("Chat")
local UserChatSuccess, CanUserChat = pcall( 
	Chat.CanUserChatAsync,
	Players,
	game.Players.LocalPlayer.UserId
)

if UserChatSuccess and not CanUserChat then
	TextChatService.OnIncomingMessage = nil
	
	script:Destroy()
end```
1 Like

you can probably fork the bubble chat module or whatever its called, since thats probably what changes it

Thats not how TextChatService works. Please look into the subject before replying.

i dont see how my suggestion wont work but ok. does TextChatService not allow you to edit the code behind it or something??

Yes, TextChatService cannot be edited by developers beyond the APIs that Roblox has directly provided to us, this is the reason why there has been so much push-back to it being forced.

3 Likes

Hey, thanks for making this post.

We’ve recently released an API analogous to TextChatService.OnBubbleAdded to support this case: TextChatService.OnChatWindow (creator hub)

You can use this new callback function to only impact how ChatWindow messages are rendered.

local TextChatService = game:GetService("TextChatService")

TextChatService.OnChatWindowAdded = function(textChatMessage)
	-- this creates a ChatWindowMessageProperties instance
	-- with properties that match ChatWindowConfiguration properties
	local properties = TextChatService.ChatWindowConfiguration:DeriveNewMessageProperties()

	-- these overrides only affect ChatWindow messages
	if textChatMessage.Text == "hi" then
		properties.TextColor3 = Color3.fromRGB(255, 255, 0)
	end
	
	return properties
end

TextChatService.OnBubbleAdded = function(textChatMessage)
	-- we'll likely add a DeriveNewMessageProperties to BubbleChatConfiguration soon
	local properties = Instance.new("BubbleChatMessageProperties")
	
	-- these overrides only affect BubbleChat messages
	if textChatMessage.Text == "hi" then
		properties.TextColor3 = Color3.fromRGB(255, 0, 0)
		
	end
	
	return properties
end

Below is a flowchart on the available options you have with callback functions with TextChatService when adjusting the default UI. Normally you’ll want to implement the more specific use cases toward the bottom of the flowchart first as the top of the of the flow chart is more “global”

Callback Return Value
TextChannel.ShouldDelieverMessage boolean?
TextChatService.OnIncomingMessage TextChatMessageProperties?
TextChannel.OnIncomingMessage TextChatMessageProperties?
TextChatService.OnBubbleAdded BubbleChatMessageProperties?
TextChatService.OnChatWindowAdded ChatWindowMessageProperties?
10 Likes

This works, thank you!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.