How would I insert Color3 Values in a table?

Hello, so I want to use Color3 values in a table to store it and then use it on Uis for my level generating kind of game.

I tried storing Color3 values into a table but only gived me numbers between 1 and 0 instead of giving me the Color3 value I stored.

All help is appreciated :smiley:

1 Like

thats because Color3.new() is different from Color3.fromRGB()
Color3.new() ranges from 0,0,0 to 1,1,1 where 0,0,0 is black and 1,1,1 is white
Color3.fromRGB() ranges from 0,0,0 to 255,255,255 where 0,0,0 is black and 255,255,255 is white

tbl["thiscolor"] = Color3.new( Color3Value.R / 255,  Color3Value.G / 255,  Color3Value.B / 255)
5 Likes

I dont think brick colors can be used in uis can they?

1 Like

Oh, just noticed that. Sorry, ignore my comment.

1 Like

Can’t you just store them like this:

local ColorTable = {
    Color3.new(),
    Color3.new(),
    Color3.new(),
    Color3.new(),
}

Or:

local ColorTable = {
    Color1 = Color3.new(),
    Color2 = Color3.new(),
    Color3 = Color3.new(),
    Color4 = Color3.new(),
}
2 Likes

probobly but I insert them. the table dosent have values right away because its a level generating kind of game like toh(tower of hell) so each round needs new colours.

1 Like

How would that work if I insert them not manually but with the table.insert function.

First of all, You seem to be missing the fact that BrickColor.Random() exsists.
This function already has random colors in it and will choose a different color for each floor.

Secondly, If you really wanted to manually insert the colors you could just insert them as arrays.
An Example:

local ColorTable = {
    Color1 = {R = 255, G = 70, B = 10},
    Color2 = {R = 100, G = 50, B = 255},
}

local function GetColor3()
    local RandomColor = ColorTable[math.random(1, #ColorTable)]
    return Color3.fromRGB(RandomColor.R, RandomColor.G, RandomColor.B)
end
3 Likes

I want to insert them with the table.insert function from a script, not manually.

1 Like

You can just do

table.insert(ColorTable, {R = 100, G = 100, B = 100}
2 Likes

Like Cosmental has said, you will have to serialize the Color3 value. You can do this two ways. Turning it into a string using tostring and then using string.sub to get the numbers or by using what Cosmental said which is the best way to do this.

2 Likes

hello i know this is an old post but i just found the solution because i was working on a project that required a table that has colors,

heres the solution
you create a color3value and then just set the color in the value ,and then just put the instance in the table heres what i did

local Colors = {
	
	script.Parent.Red.Value;
	script.Parent.Orange.Value;
	script.Parent.Yellow.Value;
	script.Parent.Green.Value;
	script.Parent.Cyan.Value;
	script.Parent.Blue.Value;
	script.Parent.Purple.Value;
	
}

and it works perfectly fine !

1 Like

Did this code work at the time of creation? Was trying to test it out with my own similar problem

1 Like

This code should still work! Just remember to multiply the values by 255 if you plan on using Color3.fromRGB. Typically, values are returned in Color3.new format.