How to detect hair

How i can detect Any types of hair?, i am doing a hat equip system, i tried using The Name of the hair But this didnt work, as Only can destroy my hair and not for others

my script :

task.wait()
local tool = script.Parent

local Storage = game:GetService("ServerStorage")
local Storage = game:GetService("ServerStorage")

local HatsFolder = Storage:WaitForChild("HatsFolder")
local event = tool:WaitForChild("Equip")

local animation = tool:WaitForChild("Ponergorra")
local cooldown = false
local Cape = HatsFolder:WaitForChild("MarineCap")

event.OnServerEvent:Connect(function(plr)
	local char = plr.Character

	local EquippedHat = char:WaitForChild("EquippedHat")

	local humanoid = char:WaitForChild("Humanoid")

	if cooldown == false and EquippedHat.Value == false then
		EquippedHat.Value = true
		cooldown = true
		local loadanim = humanoid:LoadAnimation(animation)
		--for i, v in ipairs(char:GetChildren()) do 
			--if v:IsA("Accessory") then
				--if v.Name == "Hair" then
					--local hairClone = 
					--print("Hair Detected")
					--v:Destroy()
				--end
			--end
		--end
		local HatClone = Cape:Clone()
		HatClone.Parent = char
		loadanim:Play()

		task.wait(1)
	else
		if char:WaitForChild("MarineCap") then
			local EquippedHat2 = char:WaitForChild("MarineCap")
			cooldown = false
			EquippedHat.Value = false

			local loadanim = humanoid:LoadAnimation(animation)
			loadanim:Play()

			EquippedHat2:Destroy()
			task.wait(1)
		end
	end
end)
1 Like

You could create a loop to go through all things inside the character. Then check if each thing is a Accessory & then if it’s type is Hair.

for i,v in pairs(character:GetChildren()) do
	if v:IsA('Accessory') and v.AccessoryType == Enum.AccessoryType.Hair then
		print('this is a hair')
	end
end
2 Likes