Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
1

How would I create a TextBox that changes color if it's a certain word?

Asked by 1 month ago

So basically, I want a TextBox that changes the color of the text if it's a certain string. I'm creating a Runtime GUI (basically lets you do stuff while the game is running, like banning people or kicking people from the game) and I want it to be like a script interface that changes color for what you're doing. If you don't understand what I'm saying, create a script, type "print" and you'll see that the color changes. I want that but in a TextBox. Thanks!

By the way, I know that Scripting Helpers isn't a request site, but I have no idea on where to ask this other than Scripting Helpers.

2 answers

Log in to vote
0
Answered by 1 month ago

I would use this (if someone has a better option just say)

local WordColorChange = "hello" -- i couldnt think of another variable name

script.Parent.Changed:connect(function() -- change script.parent if u have the textbox a variable
    if script.Parent.Text == WordColorChange then
        script.Parent.TextColor3= Color3.fromRGB(255,255,255)
    end
end)
0
if u want if it has a certain part of a word ill edit it PigioGigio 31 — 1mo
0
if u want if it has a certain part of a word i suggest viewing this:https://scriptinghelpers.org/questions/39155/how-to-check-if-string-contains-certain-word PigioGigio 31 — 1mo
0
btw for the color change it to ur color i just set it to white PigioGigio 31 — 1mo
Ad
Log in to vote
0
Answered by 1 month ago

you can add more to the list if you choose to. this also sets the text back to the default colour if no keyword was found.

local list = {
    example = Color3.new(1, 0, 0), -- this example would set the TextColor3 to red (255, 0, 0) if the text was "example"
};

local textbox = script.Parent:WaitForChild("TextBox");
textbox.Changed:Connect(function()
    local success = false;
    for text, colour in next, list do
        if (textbox.Text:lower() == text:lower()) then -- remove the ":lower()" on both if you want the text to be case-sensitive
            textbox.TextColor3 = colour;
            success = true;
            break;
        end
    end

    if (not success) then textbox.TextColor3 = Color3.new(); end -- if there was no keyword, set the text back to black.
end);

Answer this question