How to use rich text with a script

Hello, I’ve been trying to use rich text with a script, similar to this:

textLabel.Text = "This is sample code with <font color=rgb(255, 255, 255)> an example </font> of what I'm trying to do."
wait(1)
textLabel.Text = "You get the point, <font color=rgb(0, 19, 129)> of this </font>"

Problem is, it doesn’t show up with the text being the color I want to, it completely ignores it and the text label instead is something like “This is sample code with <font color=rgb…” and keeps in all the symbols. What’s the syntax, if any, of changing text with features from rich text using a script?

3 Likes

Since no one asked yet,i may ask since even if its simple sometimes it can be forgotten;
Is the RichText property on your text object enabled?

Yes, it’s enabled. :slight_smile:

1 Like

By closer inspection i found out you’re not using quotes to declare the color type which should be used to set the rgb

textLabel.Text = "This is sample code with <font color="rgb(255, 255, 255)"> an example </font> of what I'm trying to do."
1 Like

This doesn’t work for me. It results in an error, “attempt to call a nil value.” I’m assuming it’s resulted by rgb(255, 255, 255) not being in some type of grouping or quotes.

1 Like

Yea i didn’t take in account it was gonna be used on a script my bad…
use “[[” and “]]” instead of quotes to declare the string

This is what i used:

script.Parent.TextLabel.Text=[[This is sample code with <font color="rgb(255, 255, 255)"> an example </font> of what I'm trying to do.]]

as you can see this method works i guarantee! :sweat_smile:
image

40 Likes

Thanks! I wish this was made clearer on the official rich text post.

4 Likes

Thanks It helped me a lot for dialogs!

1 Like