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

Changing a TextLabel's TextColor using a Color3 value?

What I'm trying to do is make an easily configurable SurfaceGui. Inside the Part, there are 3 items.

SurfaceGui
Script
Configuration

Inside the configuration is

Company --StringValue
PicID --NumberValue
TextCol --Color3Value

And inside the SurfaceGui

ImageLabel
TextLabel

And finally, inside the script

local config = script.Parent.Configuration
local name = config.Company
local image = script.Parent.SurfaceGui.ImageLabel
local text = script.Parent.SurfaceGui.TextLabel
local id = config.PicID
local color = config.TextCol

while wait() do
	text.Text = name.Value --Works
	script.Parent.SurfaceGui.TextLabel.TextColor3 = Color3.new(color) --Does not work
	image.Image = "rbxassetid://"..id.Value --Works
end

2 answers

✓ Accepted answer
text.TextColor3 = color.Value

color is the color3 value, use color.Value to get the value.

1 comment

0

Oh yea, I forgot to add the value. I'm so stupid today...

The problem is that you try to pass whole color object to Color3.new function. Also, no need to make new Color3, just use it just like you did with other values.

Also, using infinite loop for this kind of updating is pretty big waste. Instead, you could make use of events, that will reduce the strain on server Lua.

local config = script.Parent.Configuration
local name = config.Company
local image = script.Parent.SurfaceGui.ImageLabel
local text = script.Parent.SurfaceGui.TextLabel
local id = config.PicID
local color = config.TextCol

-- Changed will fire everytime the value changes, so no need to pointlessly loop
name.Changed:connect(function()
	text.Text = name.Value
end)

color.Changed:connect(function()
	script.Parent.SurfaceGui.TextLabel.TextColor3 = color.Value -- Color already contains Color3
end)

id.Changed:connect(function()
	image.Image = "rbxassetid://"..id.Value
end)

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