Converting string into Color3 value?

So I have this code that prints out a string format of an RGB color value from a gui frame.
The issue is I need to also take this value and put it into a Color3Value.Value, but I’m not sure how I could go about converting this? I tried tonumber() but it doesn’t work for this case.

local textButton = script.Parent
local player = game.Players.LocalPlayer



local function selectColor()
	
	local chatcolor = player:WaitForChild("chatcolor")
	
	local color = script.Parent.Parent.ColorShower.BackgroundColor3
	local r, g, b = color.r, color.g, color.b
	local str = string.format("%0.f, %0.f, %0.f", r*255, g*255, b*255)
	print(str)
        -- I need to somehow take the str and convert it and change the chatcolor.Value with it
end

textButton.Activated:Connect(selectColor)

image

print(Color3.fromRGB(table.unpack(string.split(str, ", "))))

I wrote it in one line, but you could make it easier to read

local RGBValues = string.split(str, ", ")

print(Color3.fromRGB(table.unpack(RGBValues)))
1 Like

I tried it but for some weird reason the outputs not in RGB format, and it doesn’t affect the Color3Value.Value?
image

local function selectColor()
	
	local chatcolor = player:WaitForChild("chatcolor")
	
	local color = script.Parent.Parent.ColorShower.BackgroundColor3
	local r, g, b = color.r, color.g, color.b
	local str = string.format("%0.f, %0.f, %0.f", r*255, g*255, b*255)
	local RGBValues = Color3.fromRGB(table.unpack(string.split(str, ", ")))
	chatcolor.Value = RGBValues
	print(chatcolor.Value)
end

textButton.Activated:Connect(selectColor)

I just added it to chatcolor.Value

1 Like

In your case, please use Color3.new() constructor as you are specifying the float values of the colors.

1 Like