Creating A Code Box

Roblox supports rich text


They do not fully support rich text at the moment, I’m not sure what is the relevance of the image you posted.


Do you not see the Beta in the tweet? This will not work live in game, only in studio.


sorry I sent before the wrong image :pensive:

1 Like

if it doesnt work in-game then what’s the point of adding it?!

1 Like

It’s a beta feature so roblox can see all the bugs, if any, before it goes live in games.


It’s in Beta so then people can test it in studio and see if it works etc… and also look for bugs before being released for proper use.

1 Like

Also, that module I linked currently has way more features that roblox’s beta, and this feature most likely won’t be out of beta for a few more months.

1 Like

As @incapaz said, a lexer will be needed, and this is a bit more complicated and will take a while. A lexer takes the whole string and gives you each needed piece of text that you need. Note that in this case, you only need to lex based on each color, so whatever class/tutorial you watch, I recommend you don’t follow it exactly and make changes as needed.

So in your lexer, the following code should give you the following text:

local x = "hello there"

gives you:

x =
“hello there”

This is how I did it. After lexing, I would store the results in a table. This was a table of values which stored both the text and the word type (such as string, regular, etc). Then, I would go through the table, make a bunch of textlabels with their own colors and fonts, and put them all together.

Here is what it looks like.

Also, textservice has some useful functions for getting textsize if I remember right.


My brain cannot comprehend :rofl:

I’m not sure if I can do this since I’m not even sure what a lexer is.

It will take some time and you would need to learn it, but I’m sure there are online videos if you really want to get into it.

1 Like

There is a game “Lua Learning” made by boatbomber, this wonderful game has a code box, which supports the text that can be coloured, for instance the errors made in script. You can ask him an advice or a suggestion, he most likely tell you something about it, but he won’t give the whole code box script cause it’s a really hard work. Imagine doing a whole workable Lua code box inside the Roblox, that acts similar or almost matches the real code box in Roblox Studio.

I think the best way to contact with boatbomber is through twitter or discord or maybe through DevForum. @boatbomber

Good luck

Thanks for pinging me, @SurpriseInventor!

As someone said earlier, you need a lexer to break the text down into it’s Lua “components” aka tokens.

Lucky for you, I open sourced one!

Using that, you can run the TextBox.Text through the lexer and create colored TextLabels based on the resulting token stream for your syntax highlighting!


Now, I just checked out your script and now that i’ve seen how it works, do I need to match the tokens with a colour using a RichPresence module?

Doesn’t have to be Defaultio’s module, but yeah you’d assign a color per token and draw that using whatever module or method you want


Sorry for the late reply. I’m at school.

I was also wondering, have you had any experience in using Dafaultio’s Module?

I’m quite confused on how to use it.

Never used it, I always write my own.


With the Rich Text Markup, @cjjdawg, how would I change the colour of some text?

Just by searching on the toolbox “syntax highlighting” I found this:, and it has what you need! It is dark studio themed so you might want to change it but hopefully this helps.


I’ll make sure to check out out!