Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to save a Color3 value?

Asked by
Radstar1 270 Moderation Voter
6 years ago

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

Log in to vote
1
Answered by 6 years ago
Edited 6 years ago

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
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? Radstar1 270 — 6y
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. WillieTehWierdo200 966 — 6y
0
Awesome ty. Whats your discord man? Radstar1 270 — 6y
0
gwest2#4333 WillieTehWierdo200 966 — 6y
Ad

Answer this question