Getting RichText's rendered text?

Hello!

So I was making a dialogue system where players can talk to the NPCs.

It works like this:

  1. The player comes up to the NPC, triggering the dialogue trigger.
  2. A Dialogue GUI comes up, the dialogue system will receive the dialogue text from the NPC.
  3. A “typewriter” effect is played on the dialogue gui, alongside with audio “beeps” from the NPC. (NPCs voice) which is played when every second character in the dialogue text is revealed.

And that’s how the dialogue system works, but there is a small problem, sometimes, in a certain dialogue there are special tags which format the text (rich text tags) and the beeps pick up those special tags.

Here are some examples since I can’t really explain this properly…

Dialogue text (Normal):
"Hello, my name is [NPC's Name]!
Welcome to my shop, I sell a lot of stuff?
If you are interested in something, please tell me."

In this dialogue text, there are no rich text tags, and since the voice beeps are tied to the dialogue text’s string lenght, they will play normally, in sync with the typewriter effect. (The beeps and will finish at the same time the last character in this text is revealed by the typewriter effect.)

Dialogue text (with rich text tags):
"Wait, don't forget to bring your <font color="#FF5050">sword</font> with you!
It is <font color="FF2D00">dangerous</font> to go <b>alone</b>!"

In this text, there are rich text tags… The voice beeps will no longer play in sync with the typewriter effect because of those tags. The rendered text doesn’t have those tags, and will end way earlier, the beeps will count those tags as the dialogue text, thus breaking the illusion of the “NPC voice.” In the end, when the typewriter effect has ended, the beeps will still play for an extra 1-2 seconds, not ending at the same time as the typewriter effect.


So I had an idea, what if I can somehow only get the RichText’s rendered text, by that I won’t have any special tags, and I will be able to sync the voice beeps with the rendered text.

But is there a way to get that rendered text?

What do I mean by "rendered text"?

So lets say we have this dialogue text.

Dialogue text (with rich text tags):
"Wait, don't forget to bring your <font color="#FF5050">sword</font> with you!
It is <font color="FF2D00">dangerous</font> to go <b>alone</b>!"

The rendered text, (The text that is displayed to the player) will be.

Dialogue text (rendered):
"Wait, don't forget to bring your sword with you!
It is dangerous to go alone!"

Of course, as you could see in the rich text example, the word “sword” will be orange, “dangerous” will be red, and “alone” will be in bold.

If code snippets are needed, tell me.

This article’s great:

It gives this effect:

https://developer.roblox.com/assets/blt1c88a9240e489f16/Typewriter.mp4

1 Like

There used to be a Content property on Text Instances that allowed you to get the rendered text but because of conflicts, it was removed. You could use this as an alternative:

3 Likes

That was exactly what I was looking for!
Thanks!