Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to save a Color3 value?

I recently tried to save it, but it wouldn't let me store it in my table as it made it a dictionary. I also tried converting it to a string, but it would not let me do that either. Mainly because you can't convert (1,1,1) back to a number.

1 answer

✓ Accepted answer

Here's how you can serialize Color3 values as tables and then deserialize them back into Color3s.

local function serializeColor3(color3)
	return {color3.r, color3.g, color3.b}
end

local function deserializeColor3(serializedColor3)
	return Color3.new(unpack(serializedColor3))
end

local yellow = Color3.new(1, 1, 0)
local serializedYellow = serializeColor3(yellow) -- Save this to datastore
local deserializedYellow = deserializeColor3(serializedYellow)
print(yellow) --> 1, 1, 0
print(serializedYellow) --> table: 2F9381DC
print(deserializedYellow) --> 1, 1, 0
print(yellow == deserializedYellow) --> true

4 comments

0

This is an amazing way thank you. My friend told me to look into hexadecimals is there any way to use it doing that?

0

A significant amount of custom code would need to be written to convert Color3 values to hexadecimal (since RBXLua doesn't offer a Color3 method for this out-of-the-box), and saving them that way wouldn't offer any benefit in terms of storage size over this method, so there isn't really a reason to. But it is possible.

0

Awesome ty. Whats your discord man?

0

gwest2#4333

This discussion is preserved as it was. New answers, comments, and votes are closed.