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