This code loads in all the accessory the player own, but after all the dataStore is loaded, the player isn't spawning in with the avatar I set in the data store, no errors appear.
I also tested by removing the dataStore stuff, and it worked, but I don't know why it doesn't when I add the dataStore stuff.
--HeroThePianist
local ds = game:GetService("DataStoreService"):GetDataStore(".AccessoriesTest.")
game.Players.PlayerAdded:connect(function(plr)
local key = "id-"..plr.userId
-- DATASTORE STUFF --
ownedStuff = ds:GetAsync(key) or {
{category="SkinColor",color="Pastel brown"},
{category="Hats",ownedHats={}},
{category="Hair",ownedHair={{name="Charming Brown Hair",meshid="rbxassetid://74878559",textureid="rbxassetid://75976712",imageid="",equipped=true},{name="Normal Hair",meshid="rbxassetid://15730710",textureid="rbxassetid://20642711",imageid="",equipped=false}}},
{category="Faces",ownedFaces={{name="Smile",id="rbxasset://textures/face.png",equipped=true}}},
{category="Shirts",ownedShirts={{name="Motorcyle Shirt",textureid="rbxassetid://144076357",imageid="",equipped=true}}},
{category="T-Shirts",ownedTShirts={}},
{category="Pants",ownedPants={{name="Dark Green Jeans",textureid="rbxassetid://144076759",imageid="",equipped=true}}},
{category="Packages",ownedPackages={}}
}
plr.CanLoadCharacterAppearance = false
plr.CharacterAdded:connect(function(char)
local head = char:WaitForChild("Head")
for _,stuff in pairs(ownedStuff) do
if stuff.category == "SkinColor" then
local bodyColors = Instance.new("BodyColors",char)
bodyColors.RightArmColor = BrickColor.new(stuff.color)
bodyColors.LeftArmColor = BrickColor.new(stuff.color)
bodyColors.RightLegColor = BrickColor.new(stuff.color)
bodyColors.LeftLegColor = BrickColor.new(stuff.color)
bodyColors.TorsoColor = BrickColor.new(stuff.color)
bodyColors.HeadColor = BrickColor.new(stuff.color)
elseif stuff.category == "Hats" then
for _,hats in pairs(stuff.ownedHats) do
if hats.equipped then
-- local newHat = Instance.new("Accessory",char)
-- newHat.Name = hats.name
-- local mesh = Instance.new("SpecialMesh",newHat)
-- mesh.MeshId = ""
end
end
elseif stuff.category == "Hair" then
for _,hair in pairs(stuff.ownedHair) do
if hair.equipped then
local newHair = Instance.new("Accessory",char)
newHair.Name = hair.name
local handle = Instance.new("Part",newHair)
handle.Name = "Handle"
local attachment = Instance.new("Attachment",handle)
attachment.Position = Vector3.new(0, 0.175, 0.05)
local mesh = Instance.new("SpecialMesh",handle)
mesh.MeshId = hair.meshid
mesh.TextureId = hair.textureid
local weld = Instance.new("Weld",handle)
weld.Part0 = handle
weld.Part1 = head
end
end
elseif stuff.category == "Faces" then
for _,faces in pairs(stuff.ownedFaces) do
if faces.equipped then
if head:FindFirstChild("face") then
head.face.Texture = faces.id
print("Changed "..plr.Name.."'s face to "..faces.name)
end
end
end
elseif stuff.category == "Shirts" then
for _,shirts in pairs(stuff.ownedShirts) do
if shirts.equipped then
local newShirt = Instance.new("Shirt",char)
newShirt.Name = shirts.name
newShirt.ShirtTemplate = shirts.textureid
end
end
elseif stuff.category == "Pants" then
for _,pants in pairs(stuff.ownedPants) do
if pants.equipped then
local newPants = Instance.new("Pants",char)
newPants.Name = pants.name
newPants.PantsTemplate = pants.textureid
end
end
end
end
end)
ds:SetAsync(key,ownedStuff)
for i,v in pairs(ownedStuff) do
if v.category == "Hair" then
for _,hair in pairs(v.ownedHair) do
print(hair.name)
end
end
end
end)
game.Players.PlayerRemoving:connect(function(plr)
local key = "id-"..plr.userId
print(ownedStuff)
ds:SetAsync(key,ownedStuff)
end)

5 comments
I recommend putting datastore stuff in a pcall. Also, make sure you are NOT testing this in studio.
I did put it in pcalls, and I tested in Server mode, no luck.
Test it in the actual gameplay
@Hero I recommend that you give a small portion of where you believe the core problem is rooted at.
Update: So I have to reset the character in order to get dressed like in what I put in the ownedStuff table. This script loads in the players accessories that they own and were wearing when they previously played