Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Changing a TextLabel's TextColor using a Color3 value?

Asked by 8 years ago

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

Log in to vote
3
Answered by 8 years ago
text.TextColor3 = color.Value

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

0
Oh yea, I forgot to add the value. I'm so stupid today... TheHospitalDev 1134 — 8y
Ad
Log in to vote
1
Answered by 8 years ago

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)

Answer this question