Hats not equipping to character

I’m in the process of making a cool character customisation gui for my project.
When you click the button for the hair you want to equip, it destroys the currently existing hair, and gives the new one.
(Hairs are in the ‘Hat’ class. This is to seperate them from the ‘Accessories’ in which I use for helmets and hats.)

However, when I re-assign the parent of the Hair into the character, nothing happens.
There are no errors appearing in the output, and I have tried using Accessories instead of Hats and still no difference.

Here is the code in the “Equip” button:

local armour = script.Parent.Parent.Item.Value
n = 0
script.Parent.MouseButton1Click:Connect(function()
    
    local plr = script.Parent.Parent.Parent.Parent.Parent.Parent
    armour = script.Parent.Parent.Item.Value
	if n == 1 then
    	n = 0
	
    	if plr.Character:FindFirstChild("Hair") ~= nil then
	    	plr.Character.Hair:Destroy() -- remove existing hair
	    end
	
    	local newhelm = armour:Clone()
    	newhelm.Name = "Hair"
    	newhelm.Handle.Transparency = 1
	
	--[[
    	if the player is wearing a helmet that allows hair to be equipped too:
	    	Make it visible	      ↓↓
    	else					  ↓↓
	    	Make it invisible	  ↓↓
    --]]
	
    	if plr.Character:FindFirstChild("Helmet") ~= nil then
	    	if plr.Character.Helmet.RemoveHair.Value == true then
	    	else
	    		newhelm.Handle.Transparency = 0
	    	end	
    	else
	    	newhelm.Handle.Transparency = 0
    	end
	
    	newhelm.Parent = plr.Character -- equip the hair
	
	    script.Parent.Parent.Parent.Parent.HairV.Value = newhelm.Name
	
    	-- close up the preview frame
    	script.Parent.Parent.Visible = false
    	local g = script.Parent.Parent:GetChildren()
    	for i = 1, #g do
	    	if g[i].Name == "ItemImg" then
	    		g[i]:Destroy()
	    	end
	    end
	    wait(1)
	    n = 1
    end

end)

I don’t believe that the code is the problem, but I’m still posting it here.

Reminder: The issue is the Hat is not being equipped onto the player.

Thanks!

Try out Humanoid:AddAccessory(), might work!

I found the problem, but thank you for your time! :grin:

How did you fix the problem? (For anyone in the future with the same issue!)

4 Likes

:expressionless:

how did you fix your problem? would help alot.

replying to salcret

tell me how to fix the problem my life is on the line

4 Likes

Oh boy. I believe it had something to do with attachments inside the Handle of the accessory. Either that or I used CFrame:ToWorldSpace() and welded the hat manually.

2 Likes

Oh, thank you indeed oh great salcret. I am eternally grateful for yourself dauntlessly retorting to my importune odious request, resultantly, you have spared my imprisoned adour from the confined tides of bitter misfortune, a cruel, and dark and igor fate. I am forever indebted from thee’s gracious actions.

5 Likes