I tried to “make” custom textbox syntax highlighting like the visual studio code one, the code is not resulting in any error but it’s still not working.
Any help is appreciated!
Code:
local keywordColors = {
["if"] = Color3.fromRGB(255, 0, 0),
["then"] = Color3.fromRGB(255, 0, 0),
["end"] = Color3.fromRGB(255, 0, 0),
["function"] = Color3.fromRGB(0, 255, 0),
}
local textBox = script.Parent.Codebox
local function updateSyntaxHighlighting()
local text = textBox.Text
for keyword, color in pairs(keywordColors) do
local start, finish = 1, 1
while finish do
start, finish = string.find(text, "%f[%a_]" .. keyword .. "%f[%A_]", finish + 1)
if start then
local tag = string.format("<font color=\"#%02x%02x%02x\">", color.r * 255, color.g * 255, color.b * 255)
text = string.sub(text, 1, start - 1) .. tag ..
string.sub(text, start, finish) .. "</font>" .. string.sub(text, finish + 1)
end
end
end
textBox.RichText = true
textBox.Text = text
end
textBox.FocusLost:Connect(updateSyntaxHighlighting)
Please keep in mind that i used a little bit of “Chatgpt” to fix this code but still no success…