Lua Executor for education

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to make a code executor in game and I want the text to be color coded like a normal script.

  2. What is the issue? Include screenshots / videos if possible!
    The issue is that I can make the executor but the text isn’t color coded like it would in a real script.
    The Top Box on the right is supposed to be for code. The bottom box is the output.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I looked all over the internet and couldn’t find anything.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

https://create.roblox.com/docs/building-and-visuals/ui/rich-text

1 Like

try this

local something = {["if"] = "rgb(255,0,0)"}
local TextBox = --TextBox Here
TextBox.RichText = true
TextBox.FocusLost:Connect(function()
for i,v in ipairs(something) do
if string.find(TextBox.Text,i) then
TextBox.Text = string.gsub(TextBox.Text,something,"<font color= '"..v.."'>"..i..)
end
end
end)
1 Like

Thanks, I will try that. My goal is to make it look like a real executor and I will have it print an output when the player runs it.

Is that a Local Script or Server Script?

How did you make it do that to only specific words? This is what I want but how do you make it do that as they type the code?

TextBox:GetPropertyChangedSignal("Text"):Connect(function() --Code here. end)
You’d use the above to detect changes in the textbox’s ‘Text’ property.

If you want to use the module LuaLearning uses, you can find it here: GitHub - boatbomber/Highlighter: RichText highlighting Lua code with a pure Lua lexer (to install it look for the “Releases” button, and install the .rbxm)

For running, there is https://create.roblox.com/marketplace/asset/2783918707/Custom-Loadstring-Implimentation, but use at your own discretion.

Can explain how to use it because it is currently a module?

hmmm, i think this script can help you a bit…your idea!

local Main = script.Parent --The textbox that's player will type their scripts
local Show = Main.Show --The textlabel or something to have color :)


--If only set main,we will have inf loop,inf energy...


local All = {
	--[The Name] = "color?",
	--Not make sure it's have all
	['if'] = '#003ac1',
	['local'] = '#003ac1',
	['for'] = '#003ac1',
	['do'] = '#003ac1',
	['string'] = '#a67f00',
	['pairs'] = '#a67f00',
	['gsub'] = '#a67f00',
	['format'] = '#a67f00',
	['print'] = '#a67f00',
	['true'] = '#007f7f',
	['false'] = '#007f7f',
	['and'] = '#003ac1',
	['then'] = '#003ac1',
	['function'] = '#003ac1',
	['or'] = '#003ac1',
	['OverlapParams'] = 'a67f00',
	['new'] = '#a67f00',
	['else'] = '#003ac1',
	['elseif'] = '#003ac1',
}

--<font color= (Color) > (String) </font>
Main.TextTransparency = 1

Main:GetPropertyChangedSignal('Text'):Connect(function()
	Show.RichText = true --Set true for color,important [:
	Show.Text = Main.Text
	
	local M = Main.Text
	
	for i,v in pairs(All) do
		M = string.gsub(M,i,string.format('<font color=%q>%s</font>',v,i))
		--string.gsub('if fun then fly','if','<font color=#003ac1>if</font>')
		--^^Replace strings
		Show.Text = M
	end
end)