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

i understand there are a few posts about this, but i looked at as many as i could find and neither of those helped me figure this out, im making a datastore to save player’s outfits, how ever every time a player leaves, the script tries to save the outfits, that’s when i get this error “Cannot store Dictionary in data store. Data stores can only accept valid UTF-8 characters.”
this is the script, i understand its messy and unpractical, i’m not good at datastores yet so im making what works.

local DataStore = game:GetService("DataStoreService"):GetDataStore("PlayerOutfits")

function OnPlayerAdded(player)
	player.CharacterAdded:Wait()
	wait(0.1)

	local Outfits = nil
	local success, err = pcall(function()
		Outfits = DataStore:GetAsync(player.UserId)
	end)

	if Outfits then
		for i, v in pairs(Outfits) do
			local AvatarOutfits = player.Backpack.AvatarOutfits
			if AvatarOutfits then
				for i, v in pairs(AvatarOutfits:GetChildren()) do
					if v:IsA("Model") then
						local Description = v.Humanoid:GetAppliedDescription()
						Description.HatAccessory = Outfits["hat"..v.Name]
						Description.BackAccessory = Outfits["back"..v.Name]
						Description.FaceAccessory = Outfits["face"..v.Name]
						Description.FrontAccessory = Outfits["front"..v.Name]
						Description.HairAccessory = Outfits["hair"..v.Name]
						Description.NeckAccessory = Outfits["neck"..v.Name]
						Description.ShouldersAccessory = Outfits["shoulder"..v.Name]
						Description.WaistAccessory = Outfits["waist"..v.Name]
						Description.Face = Outfits["HeadFace"..v.Name]
						Description.Shirt = Outfits["Shirt"..v.Name]
						Description.Pants = Outfits["Pants"..v.Name]
						Description.HeadColor = Outfits["HeadColor"..v.Name]
						Description.LeftArmColor = Outfits["LeftArmColor"..v.Name]
						Description.LeftLegColor = Outfits["LeftLegColor"..v.Name]
						Description.RightArmColor = Outfits["RightArmColor"..v.Name]
						Description.RightLegColor = Outfits["RightLegColor"..v.Name]
						Description.TorsoColor = Outfits["TorsoColor"..v.Name]
					elseif v:IsA("Folder") then
						if v.Name == "Values" then
							for i,x in pairs(v:GetChlidren()) do
								for i,Values in pairs(x:GetChlidren()) do
									Values.Value = Outfits[Values.Name.."Value"..x.Name]
								end
							end
						else if v.Name == "DeleteButtons" then
								for i,x in pairs(v:GetChildren()) do
									for i,values in pairs(x:GetChildren()) do
										for i,allOutfitValues in pairs(Outfits) do
											local newButton = script.DeleteButton:Clone()
											newButton.Parent = x
											if allOutfitValues:find("Hats") then
												newButton.Name = "Hats"
												newButton.Value = Outfits["DeleteButtonHats"..x.Name]
											elseif allOutfitValues:find("Back") then
												newButton.Name = "Back"
												newButton.Value = Outfits["DeleteButtonBack"..x.Name]
											elseif allOutfitValues:find("Face") then
												newButton.Name = "Face"
												newButton.Value = Outfits["DeleteButtonFace"..x.Name]
											elseif allOutfitValues:find("Front") then
												newButton.Name = "Front"
												newButton.Value = Outfits["DeleteButtonFront"..x.Name]
											elseif allOutfitValues:find("Hair") then
												newButton.Name = "Hair"
												newButton.Value = Outfits["DeleteButtonHair"..x.Name]
											elseif allOutfitValues:find("Neck") then
												newButton.Name = "Neck"
												newButton.Value = Outfits["DeleteButtonNeck"..x.Name]
											elseif allOutfitValues:find("Shoulder") then
												newButton.Name = "Shoulder"
												newButton.Value = Outfits["DeleteButtonShoulder"..x.Name]
											elseif allOutfitValues:find("Waist") then
												newButton.Name = "Waist"
												newButton.Value = Outfits["DeleteButtonWaist"..x.Name]
											end
											newButton.Img.Image = "https://www.roblox.com/asset-thumbnail/image?assetId="..newButton.AccesorryID.Value.."&width=420&height=420&format=png"
										end
									end
								end
							end
						end
					end
				end
			end
		end
	end
	if success then
		print("Finished Loading The DataStore")
	end
	if not success then
		print("There was an error while getting data of player " .. player.Name)
		warn(err)
	end
end

function OnPlayerRemoving(player)
	local Outfits = {}
	local AvatarOutfits = player.Backpack.AvatarOutfits
	if AvatarOutfits then
		for i, v in pairs(AvatarOutfits:GetChildren()) do
			if v:IsA("Model") then
				local Description = v.Humanoid:GetAppliedDescription()
				Outfits["hat"..v.Name] = Description.HatAccessory
				Outfits["back"..v.Name] = Description.BackAccessory
				Outfits["face"..v.Name] = Description.FaceAccessory
				Outfits["front"..v.Name] = Description.FrontAccessory
				Outfits["hair"..v.Name] = Description.HairAccessory
				Outfits["neck"..v.Name] = Description.NeckAccessory
				Outfits["shoulder"..v.Name] = Description.ShouldersAccessory
				Outfits["waist"..v.Name] = Description.WaistAccessory
				Outfits["HeadFace"..v.Name] = Description.Face
				Outfits["Shirt"..v.Name] = Description.Shirt
				Outfits["Pants"..v.Name] = Description.Pants
				Outfits["HeadColor"..v.Name] = Description.HeadColor
				Outfits["LeftArmColor"..v.Name] = Description.LeftArmColor
				Outfits["LeftLegColor"..v.Name] = Description.LeftLegColor
				Outfits["RightArmColor"..v.Name] = Description.RightArmColor
				Outfits["RightLegColor"..v.Name] = Description.RightLegColor
				Outfits["TorsoColor"..v.Name] = Description.TorsoColor
			elseif v:IsA("Folder") then
				if v.Name == "Values" then
					for i,x in pairs(v:GetChildren()) do
						for i,Values in pairs(x:GetChildren()) do
							Outfits[Values.Name.."Value"..x.Name] = Values.Value
						end
					end
					else if v.Name == "DeleteButtons" then
						for i,x in pairs(v:GetChildren()) do
							for i,values in pairs(x:GetChildren()) do
								Outfits["DeleteButton"..values.Name..x.Name] = values.AccesorryID.Value
							end
						end
					end
				end
			end
		end
		local success, err = pcall(function()
			DataStore:SetAsync(player.UserId, Outfits)
		end)
		if not success then
			print("There was an error while saving data of player " .. player.Name)
			warn(err)
		end
	end
end

game.Players.PlayerAdded:Connect(OnPlayerAdded)
game.Players.PlayerRemoving:Connect(OnPlayerRemoving)

if you have any idea on what may be causing this error please tell me

It is causing this because DataStoreService only saves tables, numbers, and strings. You’re trying to save instances (outfits). You need to figure out a way to convert these accessory into strings, tables, or numbers.

i already have converted every instance into a string

this is the part that’s supposed to save the data, as you can see every instance is saved as a string and not an instance

function OnPlayerRemoving(player)
	local Outfits = {}
	local AvatarOutfits = player.Backpack.AvatarOutfits
	if AvatarOutfits then
		for i, v in pairs(AvatarOutfits:GetChildren()) do
			if v:IsA("Model") then
				local Description = v.Humanoid:GetAppliedDescription()
				Outfits["hat"..v.Name] = Description.HatAccessory
				Outfits["back"..v.Name] = Description.BackAccessory
				Outfits["face"..v.Name] = Description.FaceAccessory
				Outfits["front"..v.Name] = Description.FrontAccessory
				Outfits["hair"..v.Name] = Description.HairAccessory
				Outfits["neck"..v.Name] = Description.NeckAccessory
				Outfits["shoulder"..v.Name] = Description.ShouldersAccessory
				Outfits["waist"..v.Name] = Description.WaistAccessory
				Outfits["HeadFace"..v.Name] = Description.Face
				Outfits["Shirt"..v.Name] = Description.Shirt
				Outfits["Pants"..v.Name] = Description.Pants
				Outfits["HeadColor"..v.Name] = Description.HeadColor
				Outfits["LeftArmColor"..v.Name] = Description.LeftArmColor
				Outfits["LeftLegColor"..v.Name] = Description.LeftLegColor
				Outfits["RightArmColor"..v.Name] = Description.RightArmColor
				Outfits["RightLegColor"..v.Name] = Description.RightLegColor
				Outfits["TorsoColor"..v.Name] = Description.TorsoColor
			elseif v:IsA("Folder") then
				if v.Name == "Values" then
					for i,x in pairs(v:GetChildren()) do
						for i,Values in pairs(x:GetChildren()) do
							Outfits[Values.Name.."Value"..x.Name] = Values.Value
						end
					end
					else if v.Name == "DeleteButtons" then
						for i,x in pairs(v:GetChildren()) do
							for i,values in pairs(x:GetChildren()) do
								Outfits["DeleteButton"..values.Name..x.Name] = values.AccesorryID.Value
							end
						end
					end
				end
			end
		end
		local success, err = pcall(function()
			DataStore:SetAsync(player.UserId, Outfits)
		end)
		if not success then
			print("There was an error while saving data of player " .. player.Name)
			warn(err)
		end
	end
end

Then I think it is causing the error because you are trying to save nil. The player hat could nil.

Some players might not have certain accessories such as these

				Outfits["hat"..v.Name] = Description.HatAccessory
				Outfits["back"..v.Name] = Description.BackAccessory
				Outfits["face"..v.Name] = Description.FaceAccessory
				Outfits["front"..v.Name] = Description.FrontAccessory
				Outfits["hair"..v.Name] = Description.HairAccessory
				Outfits["neck"..v.Name] = Description.NeckAccessory
				Outfits["shoulder"..v.Name] = Description.ShouldersAccessory
				Outfits["waist"..v.Name] = Description.WaistAccessory

oh that could actually be it, ill give a try at solving that issue

You can just add if statements like this

if Description.HatAccessory ~= nil then
				Outfits["hat"..v.Name] = Description.HatAccessory
end

it still throws the error, i also looked up a number it has given me with the error which is 104, it means the data store is too large to save, so the nil might not be the issue, it might be because its too large?

That means the data store is too large to save

any idea on how to make it not so large?

You could make a separate data store for these two things. You could also make another separate data store for the body colors.

elseif v:IsA("Folder") then
				if v.Name == "Values" then
					for i,x in pairs(v:GetChildren()) do
						for i,Values in pairs(x:GetChildren()) do
							Outfits[Values.Name.."Value"..x.Name] = Values.Value
						end
					end
					else if v.Name == "DeleteButtons" then
						for i,x in pairs(v:GetChildren()) do
							for i,values in pairs(x:GetChildren()) do
								Outfits["DeleteButton"..values.Name..x.Name] = values.AccesorryID.Value
							end
						end
					end
				end
			end

Also you can’t save color3 values.

				Outfits["HeadColor"..v.Name] = Description.HeadColor
				Outfits["LeftArmColor"..v.Name] = Description.LeftArmColor
				Outfits["LeftLegColor"..v.Name] = Description.LeftLegColor
				Outfits["RightArmColor"..v.Name] = Description.RightArmColor
				Outfits["RightLegColor"..v.Name] = Description.RightLegColor
				Outfits["TorsoColor"..v.Name] = Description.TorsoColor

I’m not a data store expert though