Cannot store Dictionary in data store. Data stores can only accept valid UTF-8 characters

Hi! So I made a custom character creation system, and when they finished it, they get teleported back to the lobby. I wanna make it so when they hit ‘x’ button, the custom character they made will load back without losing any data. The problem is : I get this error :

09:06:32.823 104: Cannot store Dictionary in data store. Data stores can only accept valid UTF-8 characters. - Server - DataStore1:99

I checked out devhub + devforum, but I couldn’t really find anything.

Here is my script so far

local DataStoreService = game:GetService("DataStoreService")

local DataStoreService = game:GetService("DataStoreService")
local slot1 = DataStoreService:GetDataStore("Slot1")
local HTTP = game:GetService("HttpService")







game.Players.PlayerAdded:Connect(function(player)
	local folder = Instance.new("Folder",player)
	folder.Name = "Slot1"
	local c = game.StarterPlayer.StarterCharacter:Clone()
	c.Parent = folder
	
	local playerUserId = "Player_"..player.UserId
	local data
	local succes, errormessage = pcall(function()
		data = slot1:GetAsync(playerUserId, slot1)
	end)

	if succes then
		local data = {
			mesh = player.Slot1.StarterCharacter.Hair.Mesh;
			ofs = player.Slot1.StarterCharacter.Hair.Mesh.Offset;
			s = player.Slot1.StarterCharacter.Hair.Mesh.Scale;
			hc = player.Slot1.StarterCharacter.Hair.Color;

			sc = player.Slot1.StarterCharacter["Body Colors"].HeadColor;

			shirt = player.Slot1.StarterCharacter.Clothing.ShirtTemplate;
			pants = player.Slot1.StarterCharacter.Pants.PantsTemplate;
			class = player.Slot1.StarterCharacter.Class.Value;
			code = player.Slot1.StarterCharacter.CodeName.Value;

		}
	end
end)

game.StarterGui.InsertedObjects.Slot1.MouseButton1Up:Connect(function(player)
	local playerUserId = "Player_"..player.UserId
	local succes, errormessage = pcall(function()
		local data = {
			mesh = player.Slot1.StarterCharacter.Hair.Mesh;
			ofs = player.Slot1.StarterCharacter.Hair.Mesh.Offset;
			s = player.Slot1.StarterCharacter.Hair.Mesh.Scale;
			hc = player.Slot1.StarterCharacter.Hair.Color;

			sc = player.Slot1.StarterCharacter["Body Colors"].HeadColor;

			shirt = player.Slot1.StarterCharacter.Clothing.ShirtTemplate;
			pants = player.Slot1.StarterCharacter.Pants.PantsTemplate;
			class = player.Slot1.StarterCharacter.Class.Value;
			code = player.Slot1.StarterCharacter.CodeName.Value;

		}
		slot1:SetAsync(playerUserId, data)
	end)

	if succes then
		local data = {
			mesh = player.Slot1.StarterCharacter.Hair.Mesh;
			ofs = player.Slot1.StarterCharacter.Hair.Mesh.Offset;
			s = player.Slot1.StarterCharacter.Hair.Mesh.Scale;
			hc = player.Slot1.StarterCharacter.Hair.Color;

			sc = player.Slot1.StarterCharacter["Body Colors"].HeadColor;

			shirt = player.Slot1.StarterCharacter.Clothing.ShirtTemplate;
			pants = player.Slot1.StarterCharacter.Pants.PantsTemplate;
			class = player.Slot1.StarterCharacter.Class.Value;
			code = player.Slot1.StarterCharacter.CodeName.Value;

		}
		game.StarterGui.InsertedObjects.Slot1.Class.Text = data.class
	end
end)

game.Players.PlayerRemoving:Connect(function(player)
	local playerUserId = "Player_"..player.UserId
	local data = {
		mesh = player.Slot1.StarterCharacter.Hair.Mesh;
		ofs = player.Slot1.StarterCharacter.Hair.Mesh.Offset;
		s = player.Slot1.StarterCharacter.Hair.Mesh.Scale;
		hc = player.Slot1.StarterCharacter.Hair.Color;

		sc = player.Slot1.StarterCharacter["Body Colors"].HeadColor;

		shirt = player.Slot1.StarterCharacter.Clothing.ShirtTemplate;
		pants = player.Slot1.StarterCharacter.Pants.PantsTemplate;
		class = player.Slot1.StarterCharacter.Class.Value;
		code = player.Slot1.StarterCharacter.CodeName.Value;

	}
	local playerUserId = "Player_"..player.UserId
	slot1:SetAsync(playerUserId, data)
end)

I’m not a master of datastores, but can someone help me? I would really need it to my game.

1 Like

I can load this startercharacter from the slot1 folder, but it doesn’t save the custom character.

1 Like
sc = player.Slot1.StarterCharacter["Body Colors"].HeadColor

“HeadColor” points to a Color3 value which cannot be directly stored within a DataStore, you need to serialize this value first before storing it, for example.

local headColor = Color3.new(1, 1, 1) --White.
local headColorData = {headColor.R, headColor.G, headColor.B} --Serialized data.

When this data is loaded you can subsequently deserialize it by doing the following.

local headColor = Color3.new(table.unpack(headColorData)) --Deserialized data.

I still get the error. It’s at the last 2 line : when trying to save, it has an error

hc = player.Slot1.StarterCharacter.Hair.Color

You need to do the same with this data too.

I did it with both of them, but still.

You need to do it with all of the data values which aren’t your standard primitive types, i.e; numbers, strings, tables etc. I see a few others that serializing as well.

Still nothing. I tried to change more than just these, but still nothing.

Is there a way where I can save the startercharactermodel itself or the folder?

DataStore doesn’t save whole instances, only values such as numbers, strings and tables. It’s your job to save all data that is user-customisable into the player’s data.

Okay so I changed my script a little bit, but I printed out the values the system had to save, but nothing

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

game.Players.PlayerAdded:Connect(function(player)
	local playerUserId = player.UserId
	local folder = Instance.new("Folder",player)
	folder.Name = "Slot1"
	local c = game.StarterPlayer.StarterCharacter:Clone()
	c.Parent = folder
	
	DS:GetAsync("key", {
		mesh = player.Slot1.StarterCharacter.Hair.Mesh.MeshId,
		ofs = player.Slot1.StarterCharacter.Hair.OffsetValue.Value,
		s = player.Slot1.StarterCharacter.Hair.ScaleValue.Value,
		
		hcR = player.Slot1.StarterCharacter.Hair.Color.R,
		hcG = player.Slot1.StarterCharacter.Hair.Color.G,
		hcB = player.Slot1.StarterCharacter.Hair.Color.B,
	 

		scR = player.Slot1.StarterCharacter["Body Colors"].HeadColor.r,
		scG = player.Slot1.StarterCharacter["Body Colors"].HeadColor.g,
		scB = player.Slot1.StarterCharacter["Body Colors"].HeadColor.b,

		shirt = player.Slot1.StarterCharacter.Clothing.ShirtTemplate,
		pants = player.Slot1.StarterCharacter.Pants.PantsTemplate,
		class = player.Slot1.StarterCharacter.Class.Value,
		code = player.Slot1.StarterCharacter.CodeName.Value,
	})
end)

game.Players.PlayerRemoving:Connect(function(player)
	DS:SetAsync("key",player.UserId)
end)

I get no errors after this, and I have no idea now.