Find word in string, then colour it

I am making a custom developer console (since the F9 one doesn’t look cool enough >:(((), and I wanna make the input text be coloured. So if you typed warn, it would be orange. Or, if you typed error, it would be red.

I have… absolutely no idea how to do this. The only thing I know how to do is coloured rich text. Any ideas?

One way is to make the input box itself actually invisible, and render the typed text (plus replacements for highlighting) on top with a text label:

Sorry if this didn’t work, i’m on mobile right now

local highlighted = {
   testword = Color3.fromRGB(255,100,0)
}

local text = script.Parent.Text -- LocalScript under the TextLabel
local newtext = ""

for _, word in text:split(" ") do -- Split the words, then iterate over them
   local iscolored = false

   for i, color in highlighted do
      if word == tostrin(i) then -- Check if word needs to be highlighted
         newtext ..= '<font color="rgb("' .. color.R  .. ',' .. color.G .. ',' .. color.B .. '">' .. word .. '<\font>' .. " "
         iscolored = true
         break
      end
   end

   if not iscolored then
      newtext ..= word .. " " -- Adding Space after word
   end
end

script.Parent.Text = newtext

Edit : Whoops, didn’t mean to reply to you, sorry
But also, you can’t use richtext on TextBoxes, maybe try what nicemike40 said

Sorry for the late response. How would I make it so all of the keywords in lua are highlighted? Like print is yellow… etc.

Edit: I AM SO DUMB i just realized there’s a table in your code with all of the colours. Thank you so much!

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