You can use this module to remove the players hats excluding the hair: Accessory Module: Removing and allowing different accessory types
I do think that there is a property called âClassItemâ you can try to detect that to know that its a hair
This is quite easy to do actually! i have gone around it and found out that hair accessories use HairAttachments when they load into the playerâs character, so you can just check if the playerâs character has accessories that dont have this when they join the game, and delete them:
local Players = game:GetService("Players")
function PlayerAdded(Player)
Player.CharacterAppearanceLoaded:Connect(function(Character)
local parts = Character:GetChildren()
for i = 1, #parts do
local instanceA = parts[i]
if (instanceA.ClassName == "Accessory") then
if not instanceA.Handle:FindFirstChild("HairAttachment") then
parts[i]:Destroy()
end
end
end
end)
end
Players.PlayerAdded:Connect(PlayerAdded)
Check the attachment position. This is really the only way to make sure it is hair, otherwise its impossible.
If Iâm not mistaken, Iâm pretty sure there is a thing for this.
if I click the accessory in the explorer, There is something called âAccessoryTypeâ
This is a hat I have put on:
And this is some hair I put on:
I hope this works, nothing too much Iâm just here to give something that might be useful.
This is impossible, unless you check every single hair texture in the script, but thatâs impossible.
There is a possible way, try this.
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
repeat wait() until player.Character
for _, v in pairs(game.Workspace[player.Name]:GetChildren()) do
if v:IsA('Accessory') and not string.match(v.Name:lower(), "hair") then
local accessory = v
accessory:Destroy()
end
end
end)
end)
In addition to this solution by @Phromes :
As mentioned hereâs the docs for AccessoryTypes
Hereâs a script I wrote that strips all accessories from a character except for the hair.
function dressCharacter(character: Model)
for _, value in pairs(character:GetChildren()) do
if value.ClassName == 'Accessory' then
if value.AccessoryType ~= Enum.AccessoryType.Hair then
value:Destroy()
end
end
end
end
You could create a function specifically for this, something like this:
âInput the player into the function:
function removeHats(player)
âGet the character of the player:
local char = player.Character
âIf the character doesnât exist, return:
if not char then return end
âGet the Head of the character:
local head = char:WaitForChild(âHeadâ)
âIf the Head doesnât exist, return:
if not head then return end
âLoop through the children of the Head:
for i,v in pairs(head:GetChildren()) do
âCheck if the child is a hat:
if v:IsA(âHatâ) then
âDestroy the hat:
v:Destroy()
end
end
end
game.Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
wait(6) -- the reason i added this is because accessorys take a while to be added
for i, item in pairs(Character:GetChildren()) do
if item:IsA("Accessory") then
for i, Handlechild in pairs(item.Handle:GetChildren()) do
if Handlechild:IsA("Attachment") then -- the reason this is here is because the if statement following its will become true
if Handlechild.Name ~= "HairAttachment" then
item:Destroy()
end
end
end
end
end
Character.Humanoid.Died:Connect(function()
wait(3)
Player:LoadCharacter()
end)
end)
Player:LoadCharacter()
end)
âhereâs a better script
if v:IsA("Accessory") then
if not string.find(v.Name:lower(), "hair") then
v:Destroy()
end
end
There is a way to tell if a player has a hat accessory or hair. Inside a hair accessory there is a part called âHandleâ. And inside handle is a attachment called âHairAttachmentâ, while other accessorys have attachments called something else. You can use this to exclude hair accessorys. Like this for example,
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
wait(1)
for i, v in pairs(char:GetChildren()) do
if v:IsA("Accessory") and not v:WaitForChild("Handle"):FindFirstChild("HairAttachment") then
v:Destroy()
end
end