Hey there, Im trying to color text from a script and it seems not to be working. It does print “found” but the text in the textbox does not change colors. Please help if you can.
local keywords = {
{keyword = "local", color = Color3.new(0, 0, 1)},
{keyword = "game", color = Color3.new(1, 0.666667, 0)},
{keyword = "getservice", color = Color3.new(0, 0.666667, 1)}
}
script.Parent:GetPropertyChangedSignal("Text"):Connect(function()
local term = script.Parent.Text
if term ~= "" then
local words = term:split(",")
for _, selectedKeyword in ipairs(keywords) do
local keyword = selectedKeyword.keyword
local textColor = selectedKeyword.color
local foundWord = table.find(words, keyword)
if foundWord then
print('found')
foundWord = string.format(foundWord, '<font color="rgb(255,165,0)">%s</font>')
end
end
term = tostring(words)
end
end)
local keywords = {
{keyword = "local", color = Color3.new(0, 0, 1)},
{keyword = "game", color = Color3.new(1, 0.666667, 0)},
{keyword = "getservice", color = Color3.new(0, 0.666667, 1)}
}
script.Parent:GetPropertyChangedSignal("Text"):Connect(function()
local term = script.Parent -- Here is what I changed!
if term.Text ~= "" then
local words = term.Text:split(",")
for _, selectedKeyword in ipairs(keywords) do
local keyword = selectedKeyword.keyword
local textColor = selectedKeyword.color
local foundWord = table.find(words, keyword)
if foundWord then
print('found')
foundWord = string.format(foundWord, '<font color="rgb(255,165,0)">%s</font>')
end
end
term.Text = tostring(words)
end
end)
So, if you notice a change you should see this.
Do you see? when you storing property as a variable it will store as a variable, when you change that variable. It won’t change in property!
let’s say, you have a boolvalue in Workspace and the value is set to false!
Here’s an example:
local boolean = game.Workspace.BoolValue.Value
game.Workspace.BoolValue.Value = false
boolean = true
print(boolean) -- This will print "true"!
print(game.Workspace.BoolValue.Value) -- Well, this will print "false"
You are using string.format wrong. The first parameter should be your formatstring. So if you switch around the parameters like this it should work. foundWord = string.format('<font color="rgb(255,165,0)">%s</font>', foundWord)
I just noticed that you are trying to assign the variable words to the text, words is a table which you cant convert to a string. I’m assuming you made a logic mistake in your code here, you also don’t do anything with the variable foundWord after using string.format on it so it never gets assigned to anything.