How to save Color3 value in Datastore

I did not insult you its a joke. :face_with_hand_over_mouth:

Ok have a great day and wish you the best :happy3: :happy1:

Using .fromRGB is a lot more optimal because .new takes in doubles. Doubles (also known as floats) are decimal numbers. e.g. ‘0.1592951’ is a double, and ‘255’ is an integer.

When you store a number such as ‘0.1592951’, it’ll take up more data space. To be more precise, it takes up 9 bits of data. While on the other hand, saving ‘255’ (an integer) only takes up 3 bits of data.

Regardless of how many colours you’re saving, it’s way more optimal to save via integers rather than doubles.

p.s. Here’s the code for getting the data size of something:

-- services
local httpService = game:GetService("HttpService")

-- functions
local function dataSizeOf(this: any)
	return #httpService:JSONEncode(this) -- returns the data size in bits.
end

If you have any additional questions, ask away.

1 Like

Thanks, I wish the same for you. ;D

Your code, errors because you save 3 arguments(R, G, B) instead of one. I see a lot of people separating RGB, which is fine I guess, but the best method is to convert Color Value Into Hex. A hex is a string, so it is just one value being saved.

PRO TIP: never save data with a player.name, the Player can change the username, Instead Use Player.UserId. UserId Never changes

Players.PlayerRemoving:Connect(function(pleyer)
	local ok, eror = pcall(function()
		Datastore:SetAsync(pleyer.UserId, pleyer.info.color.Value:ToHex())
	end)
	if not ok then
		print(eror) -- line that errors
	end
end)

Here is also the way to convert a string(hex) back into a color

local success, ret = pcall(function()
	return Datastore:GetAsync(Player.UserId)
end)

if success then
	-- convert string(hex) back into a color
	Color3.fromHex(ret)
end

if not success then
	print(ret)
end

@weakmetatable

how to save as hex though

Sorry for the late response, but you can convert it to hex by color3:ToHex() and deserialize it using Color3.fromHex(color3)