Roblox TextChatService wont color correctly

Hey everyone, I haven’t asked for help in a while. Haha.

Anyways, I’m really confused and in need of some help because, I was reading this post on how to color text: How do I change System Text's Color on the new TextChatService?](How do I change System Text's Color on the new TextChatService? - #3 by be_nj):

Heres my script:

But when I do it, it won’t work.
image

Can someone help me?

2 Likes

You’re not using the textchatproperties you’ve created in the given script.

1 Like

How do I use that exactly? I was just copying the roblox administrator’s code, and it kept giving me red.

From what I remember you take your message and assign it to textchatproperties.Text and then return it from the fn

edit:

--like so:
--this colors all messages black
game.TextChatService.OnIncomingMessage = function(msg: TextChatMessage)
	local metadata = Instance.new("TextChatMessageProperties")
	metadata.Text = string.format('<font color="#000000">%s</font>', msg.Text)
	
	return metadata
end

edit: also use OnIncomingMessage on the client.

This is the result I got after trying to plug in that formula
image

injuryAnnouncementEvent.OnClientEvent:Connect(function(playerName, injuryType, sitOutTime)
	 local overrideProperties = Instance.new("TextChatMessageProperties")
	local message = Instance.new("TextChatMessageProperties")
			message.Text = string.format('<font color="#000000">%s</font>', playerName, injuryType, sitOutTime)
	systemChannel:SendAsync(message)
	
	return message
end)

no wait, you need to return it from either the TextChatService.OnIncomingMessage or the TextChannel.OnIncomingMessage callback function, which you can implement on the client, and then in your current script you just send your message normally:

injuryAnnouncementEvent.OnClientEvent:Connect(function(playerName, injuryType, sitOutTime)
	systemChannel:SendAsync(playerName)
end)

--this callback is used to decorate messages before they are displayed
--every message send from this channel will have these decorations applied
--if you want all messages to have this style use TextChatService.OnIncomingMessage instead
systemChannel.OnIncomingMessage = function(msg: TextChatMessage)
    local data = instance.new("TextChatMessageProperties")
    data.Text = string.format('<font color="#000000">%s</font>', msg.Text)

    return data
end
local TextChatService = game:GetService("TextChatService")
local systemChannel = TextChatService:WaitForChild("TextChannels"):WaitForChild("RBXSystem")
systemChannel:DisplaySystemMessage("<font color='#FF0000' face='SourceSansBold' size='24'"..
	">Your text here</font>"
)

This way is almost like creating a header then adding text to it.

image

It just shows my name, I’m sorry for the trouble. :frowning:

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

local injuryAnnouncementEvent = ReplicatedStorage:WaitForChild("IAE")
local healRE = ReplicatedStorage:WaitForChild("HealRE")
local systemChannel = TextChatService:FindFirstChild("RBXSystem") -- System channel for announcements

-- Ensure the system channel exists
if not systemChannel then
    systemChannel = Instance.new("TextChannel")
    systemChannel.Name = "RBXSystem"
	systemChannel.Parent = TextChatService
	--systemChannel.RichText = true
end

injuryAnnouncementEvent.OnClientEvent:Connect(function(playerName, injuryType, sitOutTime)
	systemChannel:SendAsync(playerName)
end)

systemChannel.OnIncomingMessage = function(msg: TextChatMessage)
    local data = Instance.new("TextChatMessageProperties")
    data.Text = string.format('<font color="#000000">%s</font>', msg.Text)

    return data
end

well it sends your name because I changed it to pass playerName to systemChannel:SendAsync because I don’t actually know what your message is sorry. Just change that to your message here:

injuryAnnouncementEvent.OnClientEvent:Connect(function(playerName, injuryType, sitOutTime)
	systemChannel:SendAsync("YOUR MESSAGE")--replace this
end)

--this callback is used to decorate messages before they are displayed
--every message send from this channel will have these decorations applied
--if you want all messages to have this style use TextChatService.OnIncomingMessage instead
systemChannel.OnIncomingMessage = function(msg: TextChatMessage)
    local data = instance.new("TextChatMessageProperties")
    data.Text = string.format('<font color="#000000">%s</font>', msg.Text)

    return data
end

im chronically stupid, or something idk

what should i put in the sendasync, because I want my message to display my

data.Text = string.format('<font color="#000000">%s</font>', msg.Text)

not my

systemChannel:SendAsync("YOUR MESSAGE")

Well do you want to display all three arguments?
You could do:

systemChannel:SendAsync(string.format("%s, %s, %d", playerName, injuryType, sitOutTime))--assuming injurytype is a string

I don’t understand what you want to send exactly, but I don’t need to know since you can just replace whatever is in the sendasync call with what you want to send

Thanks! That helps, but now I’m back at square one because it won’t color.

systemChannel:SendAsync(string.format('%s has been injured from a "<font color="#000000">%s</font>"! They must sit out for %d minute(s).', playerName, injuryType, sitOutTime))--assuming injurytype is a string

image

okay, wait can you show me your current script?

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

local injuryAnnouncementEvent = ReplicatedStorage:WaitForChild("IAE")
local healRE = ReplicatedStorage:WaitForChild("HealRE")
local systemChannel = TextChatService:FindFirstChild("RBXSystem") -- System channel for announcements

-- Ensure the system channel exists
if not systemChannel then
    systemChannel = Instance.new("TextChannel")
    systemChannel.Name = "RBXSystem"
	systemChannel.Parent = TextChatService
	--systemChannel.RichText = true
end

injuryAnnouncementEvent.OnClientEvent:Connect(function(playerName, injuryType, sitOutTime)
systemChannel:SendAsync(string.format('%s has been injured from a "<font color="#000000">%s</font>"! They must sit out for %d minute(s).', playerName, injuryType, sitOutTime))--assuming injurytype is a string
end)

systemChannel.OnIncomingMessage = function(msg: TextChatMessage)
    local data = Instance.new("TextChatMessageProperties")
    data.Text = string.format('<font color="#000000">%s</font>', msg.Text)

    return data
end

okay so I took your code and it seems like richtext doesn’t work on RBXSystem, and the only reason it worked was because you create a custom one if RBXSystem doesn’t exist, btw this is how you get RBXSystem:

local systemChannel = TextChatService:WaitForChild("TextChannels"):WaitForChild("RBXSystem")

anyway so if you create a custom textchannel instead and use that it should work.

edit: also like someone else pointed out it is better to use DisplaySystemMessage since it will not have chat bubbles pop up, it will still trigger OnIncomingMessage decorators so you don’t need to change that, although you can just use <font> directly in DisplaySystemMessage like so:

systemChannel:DisplaySystemMessage(string.format('%s has been injured by <font color="#FF0000">%s</font>. They must sit out for %d minute(s)', playerName, injureType, sitOutTime))
1 Like

image

:sob:

OHH, I FIXED IT, THANK YOU FOR UR HELP INSTEAD OF

systemChannel:SetAsync(string.format('%s has been injured from a "<font color="#000000">%s</font>"! They must sit out for %d minute(s).', playerName, injuryType, sitOutTime))--assuming injurytype is a string

YOU USE

systemChannel:DisplaySystemMessage(string.format('%s has been injured from a "<font color="#000000">%s</font>"! They must sit out for %d minute(s).', playerName, injuryType, sitOutTime))--assuming injurytype is a string

Jinx, I just figured that out at the same time as you LOL

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