Saving Color3Value to Datastore2

Hi, I am using Datastore2 to save my data and I was just wondering if it is possible to save a Color3Value as a Color3, instead of splitting it up into Color3.R , Color3.G and Color3.B?

My current Datastore script:

Players.PlayerAdded:Connect(function(player)
	--TODO: Clean this up..
	local FOVData = DataStore2("FOV" , player)
	local DayData = DataStore2("Time"  , player)
	local BrightnessData = DataStore2("Brightness"  , player)
	local WeatherData = DataStore2("Weather"  , player)
	local HoursData = DataStore2("Hours"  , player)
	local PitchColorData = DataStore2("PitchColor"  , player)
	local AngleBarData = DataStore2("AngleBar"  , player)
	local PitchTextureData = DataStore2("PitchTexture"  , player)
	local TexturesData = DataStore2("Textures"  , player)
	local SoundtrackData = DataStore2("Soundtrack"  , player)
	local CooldownData = DataStore2("Cooldown" , player)
	local BallHoldData = DataStore2("Ball_Hold" , player)
	local MotionBlurData = DataStore2("MotionBlur" , player)
	local GK_TypeData = DataStore2("GK_Type" , player)

	local Folder = Instance.new("Folder")
	Folder.Name = "Settings"
	Folder.Parent = player

	local FOV = Instance.new("IntValue")
	FOV.Name = "FOV"
	FOV.Value = FOVData:Get(70)
	FOV.Parent = Folder

	local TimeOfDay = Instance.new("IntValue")
	TimeOfDay.Name = "Time"
	TimeOfDay.Value = DayData:Get(12)
	TimeOfDay.Parent = Folder

	local Brightness = Instance.new("IntValue")
	Brightness.Name = "Brightness"
	Brightness.Value = BrightnessData:Get(0)
	Brightness.Parent = Folder

	local Weather = Instance.new("StringValue")
	Weather.Name = "Weather"
	Weather.Value = WeatherData:Get("Clear")
	Weather.Parent = Folder

	local BallHold = Instance.new("StringValue")
	BallHold.Name = "Ball_Hold"
	BallHold.Value = BallHoldData:Get("Default")
	BallHold.Parent = Folder

	local Hours = Instance.new("IntValue")
	Hours.Name = "Hours"
	Hours.Value = HoursData:Get(0)
	Hours.Parent = Folder

	local Cooldown = Instance.new("IntValue")
	Cooldown.Name = "Cooldown"
	Cooldown.Value = CooldownData:Get(0.075)
	Cooldown.Parent = Folder


	local PitchColor = Instance.new("Color3Value")
	PitchColor.Name = "PitchColor"
	PitchColor.Value = PitchColorData:Get(Color3.new(.121569, 0.501961, 0.113725))
	PitchColor.Parent = Folder

	local AngleBar = Instance.new("BoolValue")
	AngleBar.Name = "AngleBar"
	AngleBar.Value = AngleBarData:Get(false)
	AngleBar.Parent = Folder

	local PitchTexture = Instance.new("BoolValue")
	PitchTexture.Name = "PitchTexture"
	PitchTexture.Value = PitchTextureData:Get(true)
	PitchTexture.Parent = Folder


	local Textures = Instance.new("BoolValue")
	Textures.Name = "Textures"
	Textures.Value = TexturesData:Get(true)
	Textures.Parent = Folder

	local Soundtrack = Instance.new("BoolValue")
	Soundtrack.Name = "Soundtrack"
	Soundtrack.Value = SoundtrackData:Get(true)
	Soundtrack.Parent = Folder

	local GK_Type = Instance.new("BoolValue")
	GK_Type.Name = "GK_Type"
	GK_Type.Value = GK_TypeData:Get(true)
	GK_Type.Parent = Folder

	local MotionBlur = Instance.new("BoolValue")
	MotionBlur.Name = "MotionBlur"
	MotionBlur.Value = MotionBlurData:Get(false)
	MotionBlur.Parent = Folder

	for _, v in pairs(Folder:GetChildren()) do
		local Datastore = DataStore2(v.Name , player)
		
		Datastore:OnUpdate(function(NewValue)
			--if not v:IsA("Color3Value") then
				v.Value = NewValue
			--end
		end)
		
		v:GetPropertyChangedSignal("Value"):Connect(function(NewValue)
			Datastore:Set(NewValue)
		end)
	end

	task.spawn(function()
		while task.wait(1) do
			Hours.Value +=1
		end
	end)
end)

Any help would be appriciated, thanks!

I found a quick solution: changing the color3value to a string value and making the string value hold a brick color’s name. How would i convert a color3value to a brick color, as the system I am using uses color3?

Would it be possible store the independent Color3.R, Color3.G and Color3.B integers as a 3-entry table instead of a Color3 object within the datastore entry?

1 Like

Sure, I will try this thanks.
char limit

One more question, is there a way to covert a color3 into a brickcolor?

local col = Color3.fromRGB(255, 128, 60)
-- "col" is a stand-in for the specific Color3 object you have.

local color = BrickColor.new(col.R, col.G, col.B)
-- using <Color3.R, Color3.G, Color3.B> returns the exact values between 0 and 1.
-- With these three, we can create the brick color object.

print(color.Name)
-- BrickColor objects contain a "Name" value for the specific BrickColor name.

This isn’t recommended. BrickColor names do not preserve your exact RGB values at all. They default to the color value that matches the given name. For example:

local a = Color3.fromRGB(17,17,17) 
-- returns "Really Black" (default)

local b = Color3.fromRGB(0,0,0) 
-- also returns "Really Black" (developer-selected)

Really Black defaults to 17, 17, 17 (Numerical Index 1003) which is on the developer documentation page. You’ll be given default Color3 instead of the one you want.

More info: BrickColor

1 Like

You can use Color3 values for BrickColors as long as they match exactly.