How can I make a Color3 value half of another Color3?

I’m making a SurfaceGUI that has 2 TextLabels: A bright one showing information and a darker one above it as a label. What I’m trying to do is make the darker one always half as bright as the bright one. I tried writing this script inside of the darker label:

while task.wait() do
	script.Parent.BackgroundColor3.R = script.Parent.Parent.StatusLabel.BackgroundColor3.R * 0.5
	script.Parent.BackgroundColor3.G = script.Parent.Parent.StatusLabel.BackgroundColor3.G * 0.5
	script.Parent.BackgroundColor3.B = script.Parent.Parent.StatusLabel.BackgroundColor3.B * 0.5
end

I also tried other variations including trying to multiply the whole Color3 with a Vector3.
I get this error: R cannot be assigned to - Server - Script:2

How can I do this?

You can’t assign individual RGB values, you need to assign a Color3. You should also being using events instead to save performance.

Code:

local Frame = script.Parent
local StatusLabel = Frame.Parent.StatusLabel

local function SetColor()
	local statusColor = StatusLabel.BackgroundColor3
	Frame.BackgroundColor3 = Color3.new(statusColor.R / 2, statusColor.G / 2, statusColor.B / 2)
end

StatusLabel:GetPropertyChangedSignal("BackgroundColor3"):Connect(SetColor)
SetColor()

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.