Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

how to change a textcolor using a click detector?

script.Parent.MouseClick:Connect(function()
	script.Parent.Parent.BrickColor = BrickColor.Green()
	script.Parent.Parent.Parent.Status.SurfaceGui.TextLabel.Text = "Status Online"
	script.Parent.Parent.Parent.Status.SurfaceGui.TextLabel.TextColor3 = 85, 255, 0
end)

thats my script it wont work if somebody could help me that would be nice

1 comment

0

Color3.fromRGB(85, 255, 0). You made a rookie mistake.

1 answer

✓ Accepted answer

You are attempting to assign TextColor3 to 85.

Remember that in multiple assignment, additional results are silently discarded.

If you execute these, the respective outputs will be 1 nil and 1.

local v1, v2 = 1; -- v2 gets nil
print(v1, v2);

local v1 = 1, 2;
print(v1);

One of the Color3 constructors is fromRGB. It takes numbers as args ranging from 0-255.

Also, you were using script.Parent.Parent.Parent.Status.SurfaceGui.TextLabel a lot to access its properties, so why not have a variable contain a reference so it so you do not repeat yourself?

local clickDetector = script.Parent;
local part = clickDetector.Parent;
local textLabel = part.Parent.Status.SurfaceGui.TextLabel;

-- look at how cleaner it is

script.Parent.MouseClick:Connect(function()
    part.BrickColor = BrickColor.Green();
    textLabel.Text = "Status Online";
    textLabel.TextColor3 = Color3.fromRGB(85, 255, 0);
end);

Even then you shouldn't have so many .Parents. Remember to keep your code dry.

Don't

Repeat

Yourself

This discussion is preserved as it was. New answers, comments, and votes are closed.