Saving colors as strings

Hi! I think you are worked with DataStores already, or called it at least one time with the game:GetService(“DataStoreService”). If no, don’t be sad, you’ll do it, trust me.

If you already used it, and tried to save names, clothings, colors, you probably saw that saving Color3 is not a valid UTF-8 character.

Remember, that Color3 is not the only option, if you want to save the exactly 100% color, do it, but now, we are going to save it as a string.

How? I don’t want to script for hours!

What if I say you don’t have to rescript anything? What if I say you already learned this method? Yes, you did. The way we are going to use is saving the BrickColor property.

–BrickColors

BrickColors are interesting, because it’s connected to the “regular” Color3, but it can’t save a Color3.fromRGB or new(a,b,c), because this isn’t how BrickColors are working. Let’s say, I have a color : This color is red : Let’s say : Color3.fromRGB(255, 0, 0) It will be a red color due to the RGB. So the way how BrickColors are working is : There are several BrickColors :

image

These are the BrickColor icons, the colors, you probably used them. It will try to get the closest BrickColor to my Color3, and this will be the BrickColor of the part. Yes, Color3 and BrickColor are working together.

If you see it, then you found out already, that these BrickColors have names. Hold up, wait a second

Yeah, wait a second, but we are not done yet. BrickColor is not a valid property, it’s just a bigger one, it has other properties. The thing we need is the “BrickColor.Name”

And welcome to this topic, this BrickColor.Name is our string. It’s a valid UTF-8 Character, which means it’s saveable now. If you wanna make something like a player hair save, say this :

–Player Hair Save

You can say :

hairColor = player.Hair.BrickColor.Name

I’m not going to write an essay about DataStores, this isn’t why we are here.

It’s cool, let me save the BodyColors fast

Just wait a second, because they are a bit different, so for that, say :

–Player BodyColors Save

local bodyColors = player["Body Colors"].Head.Name

The reason why it’s a bit different, is BodyColors have 2 types of data : a BrickColor and a Color3 data. If you change the BrickColor, the Color3 will change too, so that’s good. The head already has a BrickColor, so we just say save its name.

And, we are done!
Please leave a comment to tell me if it’s usefull or not that good, for now bye!

3 Likes

Amazing, but tutorial like this already exists

(sorry for self promoting)

And

1 Like

Okay, I had this feeling, but since I used this way, I wanted to make a tutorial about it, and I didn’t use tables, and one of the reason I made this tutorial is : you don’t have to unpack or pack tables.

1 Like

personally I’d use colour:ToHex() to convert to a string that can be saved, and Color3.fromHex(savedString) to convert back to a Color3

if it’s a BrickColor, you can use the .Color property to access the associated Color3, and BrickColor.new(Color3.fromHex(savedString)) to restore a saved colour string, since BrickColor.new accepts a Color3

2 Likes

Yeah, but it’s an easy method, and I usually present the easy ways. This is cool too, I like it.

1 Like

I’d personally use this:

function colorToString(color) --this only works for RGB colors
       return color.R..";"..color.G..";"..color.B
end
function StringToColor(string1)
       local splitString = string.split(string1,";")
       return Color3.fromRGB(tonumber(splitString[1]),tonumber(splitString[2]),tonumber(splitString[3]))
end

Also Color3 is more customizable than BrickColor

Yeah, that’s a fact, but I personally prefer BrickColor as it’s easier to save and still have nice colors.

tbh its not that hard to save colors as string but i appreciate your work

1 Like