TextChatService question

Hey! With the new TextChatService, is there a way to change a player’s name color in chat? Instead of it defaulting to the team color, I’d like to manually set it to a custom color if possible.

Any help would be appreciated, thanks!

local function color3ToHex(color: Color3): string
	return string.format("#%02X%02X%02X", color.R * 255, color.G * 255, color.B * 255)
end


TextChatService.OnIncomingMessage = function(message: TextChatMessage)
    if not message.TextSource then return end

    local properties = Instance.new("TextChatMessageProperties")
    local player = Players:GetPlayerByUserId(message.TextSource.UserId)
    if not player then return properties end

    local color = yourColor or player.TeamColor.Color or Color3.fromRGB(255, 255, 255)

    local colorHex = color3ToHex(color)

    local ColoredPrefix = `<font color="#{colorHex}">{message.PrefixText}</font>`

    properties.PrefixText = ColoredPrefix
    properties.Text = message.Text -- u can change

    return properties
end

Something like that. I’m not sure

1 Like

If you want to hide the default chat window in Roblox’s TextChatService the easiest way is to disable it via the settings

In Studio go to StarterGui and make sure you have a Chat object there Inside it you should find the TextChatService configuration Set ChatWindowConfiguration.Enabled to false — this will prevent the default chat UI from showing up but If you’re planning to build your own chat UI you can still listen to messages with TextChatService.OnIncomingMessage and handle them however you want

But If you only want to hide the chat for some players or under certain conditions you’ll have to add some scripting to toggle that config or destroy the UI accordingly

--//Service
local TextChatService = game:GetService("TextChatService")

--//Variables
local chatWindowConfig = TextChatService:FindFirstChild("ChatWindowConfiguration")

--//Main
if chatWindowConfig then
	chatWindowConfig.Enabled = false
end

TextChatService.OnIncomingMessage:Connect(function(message)
	print("New message from", message.TextSource.Name, ":", message.Text)
end)
--!strict
--!optimize 2
local Players = game:GetService("Players")
local TextChatService = game:GetService("TextChatService")

local ToHex = BrickColor.Green().Color.ToHex::(Color:Color3)->string


TextChatService.OnIncomingMessage = function(message: TextChatMessage):TextChatMessageProperties?
	if not message.TextSource then return nil end
	
	local properties = Instance.new("TextChatMessageProperties")
	local player = Players:GetPlayerByUserId(message.TextSource.UserId)::Player?
	if not player then return properties end

	local ColoredPrefix = `<font color="#{ToHex(player.TeamColor.Color)}">{message.PrefixText}</font>`

	properties.PrefixText = ColoredPrefix
	properties.Text = message.Text

	return properties
end
2 Likes

Thanks! One more question, I was wondering if I could potentially have the players name enwrapped in square brackets like this:

[Player1]

yes just change the text to the variable “coloredprefix” you can use AI for this

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