If I wanted to take a Gui’s current color and store it into a table for later use, how would I do that?
You could do this quite simply.
You just do…
local colorTable = {}
table.insert(colorTable, guiObject.BackgroundColor3)
I’ve tried that, but when I want to use the colors to again, it just turns the Gui black. Not sure what’s going on
My attempt:
local BColor = {}
table.insert(BColor,Gui.BackgroundColor3)
print(BColor)
Gui.BackgroundColor3 = Color3.new(BColor[1],BColor[2],BColor[3])
Well, yeah that’s what is going to happen when you do this.
Instead what you want to do is…
Gui.BackgroundColor3 = BColor[1]
Try this:
local BColor = {}
BColor["Color1"] = Gui.BackgroundColor3
print(BColor)
Gui.BackgroundColor3 = BColor["Color1"]
This makes it easier to find a color.
Having a string indice like that makes no difference, and string lookups are actually going to be slower.
If you already know you are storing colors in the table, than why not just do
BColor[1] = Gui.BackgroundColor3
It’s quite of useless to have BColor["Color1"] = Gui.BackgroundColor3
, not to mention despite the decrease in efficiency being minimal it’s still something to consider.
Yes, the changes are not very noticeable, but it is more useful in a loop, large tables or if you need to encode it with JSON (not with Color3).
With this method, the gui changed to a color that is not the original (Slightly off). If I were to continue using this with let’s say a loop, I would eventually mess up the colors. Is that a roblox bug?
With this method I would have to repeat the code 3 times to get all the color values right?
Nope, the color in the array / table is stored as a color3 value, there is no need for repitition.
The same thing that happened with @SOTR654 's method happend with yours too (Colors are more and more off each use). I’m guessing this is a roblox bug
Are you using the same code or are you adding something else to it? Maybe if it’s a SurfaceGui or BillboardGui the .LightInfluence is interfering.
It’s not a roblox bug it’s how the colors are formatted when stored.
Wait nvm, was comparing the color changes by eye instead of by value. Both methods work!
You would want to convert it into a table.
{Gui.BackgroundColor3.R, Gui.BackgroundColor3.G, Gui.BackgroundColor3.B}
To get it back you would do this.
Color3.new(BColor[1], BColor[2], BColor[3])
Would I put that portion of the script in a variable?
He is just showing you how it would be stored as a subtable. This method may be prone to issues however since you will get a percentage based number stored in each table indice, which would look like…
{0, 1, 0} when stored.
Yes, you would make that table into a variable and save it. (This is basically if your going to save it with a datastore.)