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.
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```
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.
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”