Rich Text in Scripts

Problem:

I’m having issues with using rich text to change TextLabels via a local script. When the script changes the text this is what it looks like:

Intended Behaviour:

The text should change color as RichText is enabled.

Code:

local Content = script.Parent.Background.Main
local Text = Content.Text

Text.Text = string.format('Is <font color="#7289DA">%s</font> your account? If not, you can safely leave the game.', res.discordUser)

Things to Note:

  • The variable prints as expected
  • I’ve tried various other methods such as [[]] (didn’t work as I have a variable) and concatenation
  • RichText is enabled
  • The color shows up as intended when manually editing it in the GUI editor

This happens because res.discordUser contains a character used in the markup, being < - it’s treated as part of the rich text tag. Just gsub all characters like that out using their escape forms.

For example:

res.discordUser:gsub('<', '&lt;')
1 Like

Thanks a lot, this fixed my issue!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.