Help creating Rainbow text with RichText

I wanna create RGB text with richtext for some text, however its kinda hard to do it because it requires hex, and I do not want the other text in the thing also being Rainbow.
Current Text:

<font color="#ff0003">R</font><font color="#18de18">G</font><font color="#2818de">B</font>

2 Likes

You can use RGB in the font color element. Here’s an example:

<font color="rgb(255,255,255)">white text</font>

but how do I make that rainbow then?

Use a gradient on the text.

how do I use gradiants on text

Search it up. There are numerous tutorials on how to do it. Not sure why you came here before researching.

my point is I dont really want a gradiant

task.spawn(function()
	while task.wait() do
		local t = 5; 
		local hue = tick() % t / t
		local color = Color3.fromHSV(hue, 1, 1)
		script.Parent.TextColor3 = color
	end
end)

This does not require RichText to be enabled
From @Valkyrop

1 Like

I believe they want to color each letter of a label such that the label follows a rainbow pattern.

1 Like

I know this topic is old, but I thought that I would share a way to create a string of rich text that has a rainbow color pattern. This is for anyone looking for the answer in the future.

Below you can find a simple way to add rich text tags to add color:

local GRAPHEMES_PER_COLOR_LOOP = 16
local COLOR_SATURATION = .75

local function rainbowifyText(text: string): string
	local rainbowText = ""
	local currentColorIndex = Random.new():NextNumber() * GRAPHEMES_PER_COLOR_LOOP 
	for first, last in utf8.graphemes(text) do 
		local grapheme = text:sub(first, last)
		local isColoredGrapheme = grapheme~=" "
		
		rainbowText ..= if not isColoredGrapheme then grapheme else ('<font color="#%s">%s</font>'):format(
			Color3.fromHSV(currentColorIndex/GRAPHEMES_PER_COLOR_LOOP%1, COLOR_SATURATION, 1):ToHex(),
			grapheme
		)
		
		if isColoredGrapheme then
			currentColorIndex += 1
		end
	end
	return rainbowText
end

script.Parent.Text = rainbowifyText("Example Rainbow RichText!")

As you can see, the loop is for graphemes, which means that the rainbowifyText function supports any characters. This kind of loop is useful for text and can also be found in code handling typewriter effects. As you can see, for each grapheme that is not a space, a font tag is used. Each font tag has a color attribute that is the same saturation and value, but the hue goes from 0 to 1 every 16 graphemes. As you may notice, you can use Color3:ToHex() to convert a color to a hex string for the color attribute.

Anyway, using this function would yield a result like this:

5 Likes