local codebox = script.Parent
local runservice = game:GetService("RunService")
local redWords = {
"if", "local", "return", "while", "function", "end",
"and", "do", "for", "type", "typeof", "or", "until", "not",
"else", "elseif", "break", "continue", "then"
}
codebox.RichText = true
codebox.TextEditable = true
local lastText = ""
runservice.RenderStepped:Connect(function()
local inputText = codebox.Text
if inputText ~= lastText then
for _, word in pairs(redWords) do
inputText = inputText:gsub("(%f[%a])("..word..")(%f[%A])",
'<font color="rgb(255, 75, 75)">%2</font>')
end
codebox.Text = inputText
codebox.CursorPosition = #codebox.Text + 1
lastText = codebox.Text
end
end)
why does the text turn red only when the user clicks out of the text box?