How can I make words highlight in a TextBox?

So I’m trying to make a TextBox highlight keywords with different colors.

Example:

local GreenWords = {"Green","Tree","Plant"}
local BlueWords = {"Blue","Whale","Ice"}

How can I:

  • Detect if the word is in the TextBox
  • Color that word accordingly
  • Revert the word’s color if it no longer is a keyword

If I’m not quite clear, please let me know.

Hello!

I believe this is what you’re looking for: Rich Text Markup | Documentation - Roblox Creator Hub

I’m not sure if there is a way to use it like how you’ve explained, but that’s because I’ve not fiddled around with it much. If you go digging a little bit you should hopefully find what you need in this article.

Hope this helps!

:star:

1 Like

For detecting the word in the TextBox you can use string:find

local Thestring = "I want the orange candy!"
Thestring = Thestring:lower()

if Thestring:find("orange") then
   print("There's orange!")
end

For changing the color of a word you can use RichText, a property of TextLabel, TextButton, or TextBox and edit the color from there. (See the article for more information.)

1 Like

For some reason RichText breaks for me. When I focus on the TextBox, all of my text shrinks. When I focus again, resizes back to it’s original state.

a b

string.find went right over my head, thanks!

1 Like

The size of the TextBox is much larger but it still shrinks down. How can I fix this?