How to add set color to Rich text?

How can I see the color in Rich text to be based on a table of colors, thats picked at random?


local Colors = {
    Color3.fromRGB(255, 255, 255),
    Color3.fromRGB(255, 0, 0),
    Color3.fromRGB(255, 255, 0),
    Color3.fromRGB(255, 0, 255),
    Color3.fromRGB(0, 0, 255),
}

local RandomColor = Colors[math.random(1, #Colors)]

local Text = 'Color = <font color="RandomColor">'
1 Like

Use string.format to plug in the RGB values.

local Text = string.format(
    "Color = <font color=\"rgb(%d,%d,%d)\">",
    RandomColor.R*255, -- since roblox uses 0-1 values :rolling_eyes:
    RandomColor.G*255,
    RandomColor.B*255
)

I have a more complex string I was gonna post but forgot, but it doesn’t work :confused:

local FormattedString = string.format(
	"You mined a <b><font color=\"rgb(%d,%d,%d)\">" .. RandomCrystal .. "</b></font> crystal!",		
	CrystalsData.Color.R*255,
	CrystalsData.Color.G*255,
	CrystalsData.Color.B*255
)

The string just looks like this
image

So it’s not making the ‘RandomCrystal’ text be a color

Incapaz means something like this:

local Colors = {
	Color3.fromRGB(255, 255, 255),
	Color3.fromRGB(255, 0, 0),
	Color3.fromRGB(255, 255, 0),
	Color3.fromRGB(255, 0, 255),
	Color3.fromRGB(0, 0, 255),
}

local RandomColor = Colors[math.random(1, #Colors)]

local stringText = "Wakamoles"
local Text = string.format(
	"<font color=\"rgb(%d,%d,%d)\">\%s\</font>",
	RandomColor.R*255,
	RandomColor.G*255,
	RandomColor.B*255,
	stringText)

print(Text) -- This prints <font color="rbg(255,0,0)">Wakamoles</font> as example...
label.Text = Text -- Put that Text variable into a rich text label

The %d will be replaced with colors in your table and multiplied by 255 as normal html text color.
The %s will be replaced by a string given to the string.format, just be sure u close your “</font>” tag too.
Just place that formated Text variable into a Label with rich text enabled and thats it.

Tags are a stack. You need to close the last open one first.
<b><font color…> should end with </font> </b>