How can I write code in a textlabel and make it show all the colors e.t.c

So what I want is to make a textlabel show this image and i dont know how to accomplish such goal. Can someone tell me how do i do it?

2 Likes

You could use RichText

I would define the colors in variables at the top of the script.

i am also using it as a textbox so as the player inputs it changes the color (and yes I did saw some dude do it a long time ago idk where it is now)

local TextBox = script.Parent
local Words = {
	["local"] = [[<font color="#FFD700">local</font>]] -- Use HEX code for colors (google)
}

--// Loop through the TextBox and check for any matching words

while task.wait() do
	local HotText = string.split(TextBox.Text, " ") -- Splitting at spaces, making this a table
	for i,v in pairs(HotText) do
		for u,b in pairs(Words) do
			if string.lower(v) == u then
				local NewString = string.gsub(TextBox.Text, u, b)
				TextBox.Text = NewString
			end
		end
	end
end

In theory, this code should work for you, but you need to have RichText enabled.

Any issues post back here on the thread.

1 Like

i dont think anyone would waste hours on end trying to to add every single word in roblox studio knowing that i can do that but if i wanted to do that i would never had made this topic

Personally, I see no other option here if you want this to work.

welp then lets give it a try shall we?

lol


i think that also didnt worked looks like i have to do without it. thanks for the help doe

An Alternative method you could use would be having separate input and output GUI Frames, and simply use the same method I sent but put the RichText into the Output GUI Frame when the user is done.

As far as I understand the issue with this is when the textbox is in focus richtext is not in effect, so to negate that you could use this method.

What you’re looking for is a syntax highlighter. To make it, you will need a lexer/lexical analyser to tell you what the text is (string, number etc.) and a way of highlighting it. There is an amazing, open-source lexer here. I have created a highlighter that uses lots of different coloured labels, and one that uses RichText. So far, the RichText version is more performant and less memory intensive (however, the one that uses labels is kinda old and isn’t brilliantly coded). The basic outline is that it concatenates a premade string defining the RichText colour and the text that should be highlighted. Then, it is displayed on a TextLabel behind the TextBox.

Edit: After getting the link for the lexer, I realised that boatbomber has also open-sourced his highlighter module too.

wow i will look on to this thanks for helping!