Saving Color3 Values for an avatar editor

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve?

Im trying to save a few Color3 values within a data store (currently all I have are NumberValues).

  1. What is the issue?
local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("AvatarData")
local RunService = game:GetService("RunService")

local Data = {
	Face = 26424808;
	Shirt = 3750508496;
	Pants = 3;
	Hat = 151784320;
	Head = 256, 256, 256
}

local playersavetable = {};

local function loadStarterData(Player)
		local CharData = Instance.new("Folder")
		CharData.Name = "AvatarConf"
		CharData.Parent = Player
		for statname, statvalue in pairs(Data) do
			if type(statvalue) == 'number' then
			local intvalue = Instance.new("IntValue")
			intvalue.Name = statname
			intvalue.Value = statvalue
			intvalue.Parent = CharData
		end
	end
end

Here is the code, I’ll explain the issue in question 3

  1. What solutions have you tried so far?

Well first I tried adding a

	elseif type(statvalue) == 'Color3' then
	local color3 = Instance.new("Color3Value")

but despite “Color3Value” existing, it seems that ‘color3’ is not a type of statvalue.

Then I tried looking up some articles/documentation such as
https://developer.roblox.com/en-us/api-reference/lua-docs/Roblox-Globals
https://developer.roblox.com/en-us/api-reference/lua-docs/Lua-Globals
and I found this

Returns the type of its only argument, coded as a string. The possible results of this function are “nil” (a string, not the value nil), “number”, “string”, “boolean”, “table”, “function”, “thread”, and “userdata”.

so Color3 is not listed in the functions so does that mean I can’t save the body colors for legs, head, etc?

If I missed anything or if anyone has any questions then please let me know :smiley:

1 Like

If you are just saving numbers and colors, you could just use a else statement and remove the entire need for doing that. Another solution would be to wrap a color3 only accessor in a pcall, such as color.r. If it’s successful, it’s a color3.

you can save r, g, b from the colors

Do you mean save all the numbers in the color3 as separate entry? like this

Head1 = 1;
Head2 = 131;
Head3 = 31

that would be tripling the amount of request for many objects and that could slow down saving or cause total errors

That sounds good but I don’t know what it is at all, could you please provide a example on it?

You could store the color as a table, allowing you to get a different format:

local color
local colorAsTable = {color.r, color.g, color.b}

You can store tables in a data store, so that should work pretty well.
To convert the table into a color

local color = Color3.new(colorAsTable[1], colorAsTable[2], colorAsTable[3])

I’m not sure exactly what you want; But this will allow you to save the colors easily and also use the type of function to check for a table.

3 Likes

Thank you so much! I even managed to get the Color3 in the same table as the other stuff thanks to the

local color = Color3.new(colorAsTable[1], colorAsTable[2], colorAsTable[3])
1 Like