Cannot store Color3 in DataStore

  1. What do you want to achieve?
    I want to be able to store a Color3 value in a dataStore but not in the leaderstats.

  2. What is the issue?
    Im getting this error " Unable to assign property Value. Color3 expected, got number"
    Here is the value
    image

  3. What solutions have you tried so far?
    Ive tried looking on youtube, devforum and asking on the discord server

DataStore script

local DS = game:GetService("DataStoreService"):GetDataStore("Save")
local gen = game:GetService("ReplicatedStorage").Gen

game.Players.PlayerAdded:Connect(function(plr)
	
	local didjoin = false 
	local firsttime = false
	
	local success, joined =  pcall(function()
		return DS:GetAsync(plr.UserId)
	end)
	
	if success then
		if joined == 1 then 
			didJoin = true
			print("Not First Time")
		else
			DS:SetAsync(plr.UserId, 1)
			firstTime = true
			gen:FireClient(plr)
			print("First Time")
		end
	end
	
	local plrkey = "id"..plr.userId
	
	local savevalue = plr.leaderstats.Letters
	local shirtValue = plr.miscValues.shirtColor
	local isMaleValue = plr.miscValues.isMale


	local GetSaved = DS:GetAsync(plrkey)
		
	if GetSaved then
		savevalue.Value = GetSaved[1]
		shirtValue.Value = GetSaved[1]
		isMaleValue.Value = GetSaved[1]

	else
		local NumbersForSaving = {savevalue.Value}
		local NumbersForSaving2 = {shirtValue.Value}
		local NumbersForSaving3 = {isMaleValue.Value}
		DS:GetAsync(plrkey, NumbersForSaving)
		DS:GetAsync(plrkey, NumbersForSaving2)
		DS:GetAsync(plrkey, NumbersForSaving3)
		end
		
end)

game.Players.PlayerRemoving:Connect(function(plr)
	DS:SetAsync("id"..plr.userId, {plr.leaderstats.Letters.Value})
	DS:SetAsync("id"..plr.userId, {plr.miscValues.shirtColor.Value})
	DS:SetAsync("id"..plr.userId, {plr.miscValues.isisMale.Value})
end) 

leaderstats script

local DATAStoreService = game:GetService("DataStoreService")

local myDataStorage = DATAStoreService:GetDataStore("myDataScore")

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player

	local words = Instance.new("IntValue")
	words.Name = "Letters"
	
	words.Parent = leaderstats
	local leaderstats = player.leaderstats
	
	
	
	local miscValues = Instance.new("Folder")
	miscValues.Name = "miscValues"
	miscValues.Parent = player

	local shirtColor = Instance.new("Color3Value")
	shirtColor.Name = "shirtColor"
	
	shirtColor.Parent = miscValues
	
	
	
	local isMale = Instance.new("BoolValue")
	isMale.Name = "isMale"

	isMale.Parent = miscValues

	local miscValues = player.miscValues
end)

Theres also a error called
104: Cannot store Array in data store. Data stores can only accept valid UTF-8 characters.
but I think it will dissapear once I store the Color3 correctly

A Color3Value requires a Color3 data type in order to change its value.

if GetSaved then
		savevalue.Value = GetSaved[1]
		shirtValue.Value = Color3.fromRGB(GetSaved[1])
		isMaleValue.Value = GetSaved[1]

	else

Yup, you’d have to save the Color3 as numbers inside your Datastore.

It fixed the error but it stores them weirdly, do I have to reverse the changes somehow to fix this?


(The color should be pink)
Before I left I checked the color and it was pink

Did you save the shirtColor’s value as a single number?

What do you mean by a single number?

This is the only script that can change the value
localscript

game:GetService("ReplicatedStorage").ApplyColor:FireServer(script.Parent.ColourDisplay.ImageColor3)

server script

Event.ApplyColor.OnServerEvent:Connect(function(plr, color)
	
	plr.Character.Torso.Color = color
	plr.miscValues.shirtColor.Value = color
	
end)
local DS = game:GetService("DataStoreService"):GetDataStore("Save")
local gen = game:GetService("ReplicatedStorage").Gen

game.Players.PlayerAdded:Connect(function(plr)
	
	local didjoin = false 
	local firsttime = false
	
	local success, joined =  pcall(function()
		return DS:GetAsync(plr.UserId)
	end)
	
	if success then
		if joined == 1 then 
			didJoin = true
			print("Not First Time")
		else
			DS:SetAsync(plr.UserId, 1)
			firstTime = true
			gen:FireClient(plr)
			print("First Time")
		end
	end
	
	local plrkey = "id"..plr.userId
	
	local savevalue = plr.leaderstats.Letters
	local shirtValue = plr.miscValues.shirtColor
	local isMaleValue = plr.miscValues.isMale


	local GetSaved = DS:GetAsync(plrkey)
		
	if GetSaved then
	local shirtColorValue = GetSaved[1]["ShirtColors"]
	
	savevalue.Value = GetSaved[1]
	shirtValue.Value = Color3.fromRGB(shirtColorValue["R"], shirtColorValue["G"], shirtColorValue["B"])
	isMaleValue.Value = GetSaved[1]
else
		local NumbersForSaving = {savevalue.Value}
		local NumbersForSaving2 = {shirtValue.Value}
		local NumbersForSaving3 = {isMaleValue.Value}
		DS:GetAsync(plrkey, NumbersForSaving)
		DS:GetAsync(plrkey, NumbersForSaving2)
		DS:GetAsync(plrkey, NumbersForSaving3)
		end
		
end)

game.Players.PlayerRemoving:Connect(function(plr)
	local plrShirtColor = plr.miscValues.shirtColor
	local shirtColors = {
		["ShirtColors"] = {
			["R"] = plrShirtColor.Value.R;
			["G"] = plrShirtColor.Value.G;
			["B"] = plrShirtColor.Value.B;
		}	
	}

	DS:SetAsync("id"..plr.userId, {plr.leaderstats.Letters.Value})
	DS:SetAsync("id"..plr.userId, {shirtColors})
	DS:SetAsync("id"..plr.userId, {plr.miscValues.isisMale.Value})
end)

I’m not 100% sure if that’ll work for not as I haven’t tested it out, let me know

" ServerScriptService.SaveData:35: attempt to index boolean with ‘ShirtColors’ - Server - SaveData:35"
I think u meant [shirtValue.Value] but that didnt work neither

Try replacing:
local shirtColorValue = GetSaved[1]["ShirtColors"]

With:
local shirtColorValue = GetSaved["ShirtColors"]

What I’m mainly confused by is how you retrieve your data as for savevalue and isMaleValue, by getting the first index from your Datastore

“ServerScriptService.SaveData:38: attempt to index nil with number - Server - SaveData:38”
I think my script is just cursed

local DS = game:GetService("DataStoreService"):GetDataStore("Save")

game.Players.PlayerAdded:Connect(function(plr)

	local didjoin = false 
	local firsttime = false

	local success, joined =  pcall(function()
		return DS:GetAsync(plr.UserId)
	end)

	if success then
		if joined == 1 then 
			print("Not First Time")
		else
			DS:SetAsync(plr.UserId, 1)
			print("First Time")
		end
	end

	local plrkey = "id"..plr.userId

	local savevalue = plr.leaderstats.Letters
	local shirtValue = plr.miscValues.shirtColor
	local isMaleValue = plr.miscValues.isMale


	local GetSaved = DS:GetAsync(plrkey)

	if GetSaved then
		local shirtColorValue = GetSaved[1]["ShirtColors"]
		
		savevalue.Value = GetSaved[1]
		shirtValue.Value = Color3.fromRGB(shirtColorValue["R"], shirtColorValue["G"], shirtColorValue["B"])
		isMaleValue.Value = GetSaved[1]
	else
		local shirtColors = {
			["ShirtColors"] = {
				["R"] = shirtValue.Value.R;
				["G"] = shirtValue.Value.G;
				["B"] = shirtValue.Value.B;
			}	
		}
		
		local NumbersForSaving = {savevalue.Value}
		local NumbersForSaving2 = {shirtColors}
		local NumbersForSaving3 = {isMaleValue.Value}
		DS:GetAsync(plrkey, NumbersForSaving)
		DS:GetAsync(plrkey, NumbersForSaving2)
		DS:GetAsync(plrkey, NumbersForSaving3)
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	local plrShirtColor = plr.miscValues.shirtColor
	local shirtColors = {
		["ShirtColors"] = {
			["R"] = plrShirtColor.Value.R;
			["G"] = plrShirtColor.Value.G;
			["B"] = plrShirtColor.Value.B;
		}	
	}

	DS:SetAsync("id"..plr.userId, {plr.leaderstats.Letters.Value})
	DS:SetAsync("id"..plr.userId, {shirtColors})
	DS:SetAsync("id"..plr.userId, {plr.miscValues.isisMale.Value})
end)

This works fine on my end. Again, let me know if it throws anymore errors

I ended up rewriting the entire dataStore but thanks