How would you make a TextChatService SystemMessage Colored with a variable?

What I mean is like

game.ReplicatedStorage.Message.OnClientEvent:Connect(function(msg, color)
	game.TextChatService.TextChannels.RBXSystem:DisplaySystemMessage("<font color=\"rgb("..color..")\">".. msg.."</font> ")
end)

But obviously, this won’t work when you do like .. color ..

How could I do this using TextChatService

1 Like

Use Color.toRGB. This function returns tuple of values.

image
This is the value it is sending to the RemoteEvent.

Secondly, I have tried it already.

Also, there is no toRGB

I have tried the methods that work with RGB values (all of them) in Color3

Then it wants it to a string and when I do that it says in the chat, things such as:

image

Above image uses this script:

game.ReplicatedStorage.Message.OnClientEvent:Connect(function(msg, color)
	--if game.Players.LocalPlayer.ServerMessages.Value == true then
	game.TextChatService.TextChannels.RBXSystem:DisplaySystemMessage("<font color=\"rgb(".. color.R .. ", " .. color.G .. ", " .. color.B ..")\">".. msg.."</font> ")
end)

Then I tried doing like it with tostring.

but still not working

Are you sure that chat supports rtf?

That is how TextChatService System Messages work. For instance, this script:

game.TextChatService.TextChannels.RBXSystem:DisplaySystemMessage("<font color=\"rgb("..tostring(Color3.new(255, 0, 0))..")\">"..msg.."</font> ")--	end

Would look like this:

image

Then just do

game.ReplicatedStorage.Message.OnClientEvent:Connect(function(msg, color)
	game.TextChatService.TextChannels.RBXSystem:DisplaySystemMessage("<font color=\"rgb("..Color3.new(color.R, color.G, color.B)..")\">".. msg.."</font> ")
end)

When I sent my previous reply, I thought exactly the same and that’s what I am trying right now.

game.ReplicatedStorage.Message.OnClientEvent:Connect(function(msg, color)
	game.TextChatService.TextChannels.RBXSystem:DisplaySystemMessage("<font color=\"rgb("..Color3.new(color.R, color.G, color.B)..")\">".. msg.."</font> ")
end)

=

Workspace.DecentAgent.MessageHandler:3: attempt to concatenate Color3 with string

I added tostring() then:

game.ReplicatedStorage.Message.OnClientEvent:Connect(function(msg, color)
	--if game.Players.LocalPlayer.ServerMessages.Value == true then
	game.TextChatService.TextChannels.RBXSystem:DisplaySystemMessage("<font color=\"rgb("..tostring(Color3.new(color.R, color.G, color.B))..")\">".. msg.."</font> ")
end)

and nothing is being sent out in the chat then

These are the color values btw

Maybe try printing the color to see if it works.

1 Like

One of the easiest ways to add font color is in hex format, so you could convert it.

Here’s a solution with string interpolation:

RBXSystem:DisplaySystemMessage(`<font color=\"#{color:ToHex()}">{msg}</font>`)

ToHex doesn’t prefix the return with a hashtag, so you have to add it yourself.


Update: follow up!

Apparently there is a bug with ToHex() that is currently being handled. Until this is solved, there’s a chance ToHex() throws an error in some cases on some platforms.

Let’s go back to RGB then.

Color3 is not RGB (1-255, 1-255, 1-255), it’s (0-1, 0-1, 0-1).

It’s fairly simple to convert the values and build a string.

function Color3ToRGB(color3)
	return math.round(color3.R*255), math.round(color3.G*255), math.round(color3.B*255)
end

local rgbString = string.format("rgb(%s, %s, %s)", Color3ToRGB(color))

RBXSystem:DisplaySystemMessage(`<font color=\"{rgbString}\">{msg}</font>`)
2 Likes

Thank you, it worked!

image

1 Like