Custom character system not working

I want to create a race system (similar to rogue lineage). The player will have some accessories removed, and others not. For example, only the player’s hair will stay. The issue is, the player will sometimes still have hats, even though I am removing them. I have tried different solutions, (for loops, humanoid descriptions) and none seem to fix the issue. I have not seen any posts similar to this.

This code is run in a module after the character is added.

function CharacterSetup:SetupApperance(Player,Race,Clothes,LastName)
	local Character = Player.Character or Player.CharacterAdded:Wait()
	local Humanoid = Character:WaitForChild("Humanoid")
	Player.CharacterAppearanceLoaded:Wait()
	repeat task.wait() until Character:FindFirstChild("Humanoid"):FindFirstChild("HumanoidDescription")
	--Body Parts--
	local humanoidDescription = Humanoid:GetAppliedDescription() -- remove package
	humanoidDescription.Head = 0
	humanoidDescription.Torso = 0
	humanoidDescription.RightLeg = 0
	humanoidDescription.LeftLeg = 0
	humanoidDescription.RightArm = 0
	humanoidDescription.LeftArm = 0
	humanoidDescription.HatAccessory = ""
	humanoidDescription.BackAccessory = ""
	humanoidDescription.FrontAccessory = ""
	humanoidDescription.NeckAccessory = ""
	humanoidDescription.ShouldersAccessory = ""
	humanoidDescription.WaistAccessory = ""
	Humanoid:ApplyDescription(humanoidDescription)

try

player.Character.Humanoid:RemoveAccessories()

Make sure you also wait for the character’s appearance to be loaded in before you make any changes

player.CharacterAppearanceLoaded:Wait()

I don’t want to do this, as it removes all accesories. I want the player’s hair to still stay.

I already do this at the beginning, and it still sometimes has the character’s accessories despite that.

I fixed it. For whatever reason the appearance loaded was waiting forever.

if not Player:HasAppearanceLoaded() then Player.CharacterAppearanceLoaded:Wait() end

Check if the character’s appearance hasn’t loaded first before attempting to wait for it to load.