DataStoreService doesn't save dictionaries (or something else?)

Sup devs,

I was writing a DataStore system earlier, then I got a error showing :

DataStoreService: CantStoreValue: Cannot store Dictionary in data store. Data stores can only accept valid UTF-8 characters. API: SetAsync, Data Store: PlayerData

This problem occured when I’m writing the SetAsync() function, here is part of the code for reference :

function DS:SaveData(plr : Player)
	local AD = plr:WaitForChild("AvatarData")
	
	print({AD.HeadColor.Value}) -- For debugging, everything was normal
	
    -- The problem should be here
	local data = {
		["AvatarData"] = {
            -- The Color3 values are converted to an array for saving
            -- I don't think there are problems here though
			["HeadColor"] = {AD.HeadColor.Value}, 
			["ArmsColor"] = {AD.ArmsColor.Value},
			["TorsoColor"] = {AD.TorsoColor.Value},
			["LegsColor"] = {AD.LegsColor.Value}
		}
	}
	
	for i = 1, 10 do
		local success, data = pcall(function()
			return PlayerData:SetAsync(plr.UserId, data)
		end)
		
		if success then
		    return
		else
			output(warn, "Failed to save data for "..plr.Name..", retrying, attempt : "..i)
		end
	end
end

Any help is appreciated!!

You are attempting to save a color value, datastores can only save tables, booleans, numbers and strings. You could convert the color to hex using :ToHex() and save it like that.

I have mentioned that Color3 values are converted to tables before storing, or did I misunderstood your meaning?

Sorry for not seeing that, the problem probably arises from there though. Could you print out “data” for more debugging?

{
                    ["AvatarData"] =  ▼  {
                       ["ArmsColor"] =  ▼  {
                          [1] = 0.960784, 0.803922, 0.188235
                       },
                       ["HeadColor"] =  ▼  {
                          [1] = 0.960784, 0.803922, 0.188235
                       },
                       ["LegsColor"] =  ▼  {
                          [1] = 0.643137, 0.741176, 0.278431
                       },
                       ["TorsoColor"] =  ▼  {
                          [1] = 0.0509804, 0.411765, 0.67451
                       }
                    }
                 }

Here you are

1 Like

That is probably causing the issue could you try removing the index ([1] in this case) and try again? Also converting to Hex would be much more easier.

1 Like

Output automatically puts a number index in front of every data in an array even when no index is given, I don’t think that matters.

Just realized, you are directly setting these from a Color3 value am I correct? If so this won’t work, try converting them to strings or hex. If you are using a string value for this, then there is likely another issue that is unrelated.

2 Likes

Saving it as a Hex string indeed works, thanks for your help!

2 Likes