Color3 ingores other Colors(R,B for example) which aren't selected now(G for example)

For unknown reason my code ingoners other colors.
For example i change Red color and it starts to ingores Blue and Green.
Like if i change first Blue to max then Green to max then it gonna be fully green with 0 of blue.
Like it doesn’t ingore just color which just was changed.
I tried to make print and to change every color in game menu, and after i changed Red to max then Blue to max and then Green to max it prints that Color3Value = 3.63713e-15, 1, 6.03086e-08
I use Local Script in StarterGui.
Here is my script:

local CarColorValue = script.Parent:WaitForChild("CarColor")
local RedTextBox = script.Parent:WaitForChild("Red")
local BlueTextBox = script.Parent:WaitForChild("Blue")
local GreenTextBox = script.Parent:WaitForChild("Green")
local function RedChanged()
	if tonumber(RedTextBox.Text) ~= nil then
		local NeededColor = Color3.fromRGB(math.clamp(RedTextBox.Text,0,255),CarColorValue.Value.G,CarColorValue.Value.B)
		CarColorValue.Value = NeededColor
	end
end
local function BlueChanged()
	if tonumber(BlueTextBox.Text) ~= nil then
		local NeededColor = Color3.fromRGB(CarColorValue.Value.R,CarColorValue.Value.G,math.clamp(BlueTextBox.Text,0,255))
		CarColorValue.Value = NeededColor
	end
end
local function GreenChanged()
	if tonumber(GreenTextBox.Text) ~= nil then
		local NeededColor = Color3.fromRGB(CarColorValue.Value.R,math.clamp(GreenTextBox.Text,0,255),CarColorValue.Value.B)
		CarColorValue.Value = NeededColor
	end
end
RedTextBox:GetPropertyChangedSignal("Text"):Connect(RedChanged)
BlueTextBox:GetPropertyChangedSignal("Text"):Connect(BlueChanged)
GreenTextBox:GetPropertyChangedSignal("Text"):Connect(GreenChanged)

that’s because Color3 values are not fromRGB and are between 0 and 1 so when green is max, the value in CarColorValue for green is 1, but when you try to set it with fromRGB you’re only giving it 1 instead of 255. I don’t know if that makes sense if you read it like that. But to understand better here is what you should do :

local NeededColor = Color3.fromRGB(CarColorValue.Value.R * 255 ,CarColorValue.Value.G * 255,math.clamp(BlueTextBox.Text,0,255))

do the same for all the 3 functions. Multiply the value by 255 so it’s actually an RGB value.

1 Like

Thx, it worked. I thought on it already, but watched to Value and it show it as from 0,0,0 to 255,255,255 so i thought something wrong with my script.

yea it’s tricky it shows RGB values but prints differently. Anyway glad it worked!

1 Like

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