Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make a specific text have different color in a GUI?

Asked by 3 years ago

I have tried string.color, but I realized that string.color isn't a thing anymore.

local TextLabel = script.Parent
TextLabel.Text = "Hello"
local TextToColor = string.find(TextLabel.Text, "He")
TextToColor.Color3 = Color3.new(1, 1, 1)

I want the "llo" part in "Hello" to be black, and the "He" part to be white, but it always prints this:

"TextLabel.LocalScript:4: attempt to index number with 'Color3'"

0
Change the TextToColor.Color3 variable into TextToColor. That worked for me CountOnMeBro 51 — 3y

2 answers

Log in to vote
2
Answered by
2_MMZ 1059 Moderation Voter
3 years ago

The easiest way to change color for your text is TextColor3

Here's a script for you.

script.Parent.Text = "Hello"
local TextToColor = string.find(TextLabel.Text, "He")
TextToColor.TextColor3 = Color3.new(1, 1, 1,)
0
I put your script, and it says "TextLabel.LocalScript:4: attempt to index number with 'TextColor3' " pepsymax 73 — 3y
Ad
Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

To change particular parts of text you need to use RichText, which you can enable on your TextButton/TextLabel/TextBox in the properties window. In order to make it a different color you would input something like so...

-- Turns 'He' red
script.Parent.Text = '<font color="rgb(255,0,0)">He</font>llo'

Your example...

script.Parent.Text = '<font color="rgb(255,255,255)">He</font><font color="rgb(0,0,0)">llo</font>'
0
Let me try that give me a second pepsymax 73 — 3y
0
It doesn't work i tried the Richtext property on and off with the script and without rich text the textlabel said "'<font color="rgb(255,0,0)">He</font>llo'" and with the richtext all it did was just say hello and nothing else the colors didn't work pepsymax 73 — 3y

Answer this question