Textcolor Issue

Code:

local textcolor = script.Parent.SurfaceGui.TextButton.TextColor3
local click = script.Parent.ClickDetector
local red = Color3.fromRGB(255, 0, 0)

click.MouseClick:Connect(function()
	textcolor = red
end)

The code is housed inside a normal script.

explorer

For some reason, it is not working. No errors are showing up in output. What I would like it to do is for the part to make the textcolor of the text label (named text button) turn red.

Does anyone have any solutions?

1 Like

(post marked for deletion for privacy reasons)

1 Like

You are only changing the variable textcolor, not the actual color.

local button = script.Parent.SurfaceGui.TextButton


button.TextColor3 = red
1 Like

No, button returns (script.Parent.SurfaceGui.TextButton) in the workspace, using a variable like :
button.TextColor3 = red
will be translated to
script.Parent.SurfaceGui.TextButton.TextColor3 = red

I don’t understand what you mean.

I’ve had a similar issue before (Or so i believe).

Would you mind adding a print when it gets clicked and let me know if it prints or not?

It doesn’t change the variable’s textcolor… (why would it?)
It changes script.Parent.SurfaceGui.TextButton since button is assigned as script.Parent.SurfaceGui.TextButton,

If you try doing:
print(button)
It’ll return:
script.Parent.SurfaceGui.TextButton

Calling the variable’s name, returns what’s assigned to the variable.

It changes the variable called textcolor

button is a variable I created, so I’m still not sure what you’re trying to inform me about.

button is the TextButton, a variable I created. By changing button.TextColor3, you are changing the actual TextColor3 as intended.
textcolor is (for anyone else reading this) a copy of TextColor3. By changing the variable textcolor, you are only changing the variable and not the actual TextColor3

Ooh, I thought you were talking about “button” srry :sweat_smile:

1 Like