Hello, so I have this code that removes your accessories and replaces the old hair with a new hair. I have done some research but cant find out how to only remove the hat and hair accessories. Any help?
local ChangeHairRemote = game.ReplicatedStorage.ChangeHair
local HairModels = game.ReplicatedStorage.Hair
ChangeHairRemote.OnServerEvent:Connect(function(Player, TargetCharacter)
for _, object:Instance in ipairs(TargetCharacter:GetDescendants()) do
if (object:IsA("Accessory") == true) then
object:Destroy()
end
end
local NewHair = HairModels[math.random(1, 20)]:Clone()
NewHair.Parent = TargetCharacter
NewHair.Weld.Part1 = TargetCharacter.Head
NewHair.Weld.Part0 = NewHair.Hair
end)
Okay I found out what you meant, you could use AccessoryType for this:
local ChangeHairRemote = game.ReplicatedStorage.ChangeHair
local HairModels = game.ReplicatedStorage.Hair
ChangeHairRemote.OnServerEvent:Connect(function(Player, TargetCharacter)
for i, v in pairs(TargetCharacter:GetChildren()) do
if v:IsA("Accessory") then
if v.AccessoryType == Enum.AccessoryType.Hat or v.AccessoryType == Enum.AccessoryType.Hair then
v:Destroy()
end
end
local NewHair = HairModels[math.random(1, 20)]:Clone()
NewHair.Parent = TargetCharacter
NewHair.Weld.Part1 = TargetCharacter.Head
NewHair.Weld.Part0 = NewHair.Hair
end
end
You can also use AccessoryType to find out what other accessories are which you can find in the documentation