Adding "," to a number?

So I am trying to convert this string into a color3 value. I’ve got it to split into three different values but I
dont know how I can add “,” between each number

String (base): ['Base'] = "411/75/236",

local br = string.split(base, "/")[1]
local bg = string.split(base, "/")[2]
local bb = string.split(base, "/")[3]
local bf = tonumber()

If your wondering where base comes from its from a modulescript thats then fired through an remote.

```local config = {
	['Settings'] = 
	{
		['GroupId'] = 4311276,
		['Prefix'] = ".",
		['Type'] = '>=',
		['Base'] = "411/75/236",
		['Shader'] = "33/145/193",
		['Transparency'] = 0.5,
		
	},
}
return config
1 Like

That’s not how Color3s work. You can make a Color3 by using a constructor function, it isn’t just a string or numbers with commas in between. For Color3s, there are three constructor functions which can be found here. Color3 | Documentation - Roblox Creator Hub

explaining the wiki since the descriptions aren't the best

The constructor function Color3.new() is used like this: local color = Color3.new(r, g, b). It will create a Color3 where r is the red component, g is the green component, and b is the blue component. r g and b have to range from 0-1 for this to work properly.

Color3.fromRGB() is very similar except r, g and b can range anywhere from 0 to 255.

There’s a third constructor function, which is Color3.fromHSV() and is used like this: local color = Color3.fromHSV(h, s, v). It’s useful for a different way to specify a color. Like Color3.new, its values can range from 0-1. Unlike the other two functions, it is based on hue, saturation, and value. The h represents hue, which basically decides which color it is. The s represents saturation, which decides how bright/non-gray it is; when saturation is 0, the color will be a shade of gray regardless of the hue value. The v is “value”, which is basically how bright it is. If v is zero, the color will always be black, no matter what h and s are.

1 Like

base = base:gsub("/", ",") will replace the /s between the numbers with commas between the numbers, but you want to get a Color3 and adding commas won’t do anything. Color3.fromRGB(base:match("(%d+).(%d+).(%d+)")) will capture the 3 delimiter-separated numbers and pass them to the Color3 constructor.

using string.split: Color3.fromRGB(unpack(base:split("/")))

2 Likes

I honestly don’t understand. Every time I use your line of code it prints the 3 numbers with a space in between

1 Like

Could I have an example? Please.

If you’re printing the color3 object then that’s because it calls tostring on it and calling tostring on a color3 object prints the components separated by a space.

base = "255/255/255"
base = base:gsub("/", ",")

turns "255/255/255" into "255,255,255" (a string, not a Color3 object)

1 Like
local r = base:gsub("/", ",")
print(r)
wait(0.1)
storage.Header.BackgroundColor3 = Color3.fromRGB(r)
storage.Header.Body.BackgroundColor3 = Color3.fromRGB(r)

Then how would I get it to a Color3 value?

1 Like

https://developer.roblox.com/api-reference/datatype/Color3

The Color3.fromRGB constructor takes 3 numbers as arguments. You need to turn the string into 3 numbers and pass the 3 numbers instead of the string. You already got them in the first 3 lines of code in the OP; Color3.fromRGB(br, bg, bb) would construct the Color3 object from those 3 components.

Oh I understand now i’l try using split.

1 Like

Still having problems, I think im misisng something.

local br = string.split(base, "/")[1]
local bg = string.split(base, "/")[2]
local bb = string.split(base, "/")[3]
print(br.. ",".. bg.. ",".. bb)
wait(0.1)
storage.Header.BackgroundColor3 = Color3.fromRGB(br, bg, bb)

Im getting a werid purple color, when its supposed to be blue,
Capture
image

The “Base” string in the table is "411/75/236". The r component is 411, which is outside the [0, 255] range, so it overflows to 155, 75, 236 instead, which is purple. If it were 41 or 11 instead of 411 then it would be blue.

1 Like

Thanks alot man, I finally got it working. Sorry for the disrupting you btw this question is most likely a waste of your time.