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:
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
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: