I’m trying to have all accessories except hair be deleted and I made a script and put it into the StarterPack folder.
local char = script.Parent.Parent.Character
for _,v in pairs(char:GetChildren()) do
print("1")
if v:IsA("Accessory") then
print("2")
if v.AccessoryType:IsA("Hair") then
print("3")
else
v:Destroy()
print("4")
end
end
end
Am I missing something or what? It only prints the 1.
Maybe try to put the script in StarterCharacterScript?
local char = script.Parent
for _,v in pairs(char:GetChildren()) do
print(v)
if v:IsA("Accessory") then
print("2")
if v.AccessoryType:IsA("Hair") then
print("3")
else
v:Destroy()
print("4")
end
end
end
:IsA is for instance, AccessoryType is a property of acessory and it gives you an enum value. if v.AccessoryType ~= Enum.AccessoryType.Hair then v:Destroy end
local char = script.Parent.Parent.Character
for _,v in pairs(char:GetChildren()) do
print("1")
if v:IsA("Accessory") then
print("2")
if v.AccessoryType == Enum.AccessoryType.Hair then
print("3")
else
v:Destroy()
print("4")
end
end
end
Also, if you’re interested Humanoid’s have a GetAccessories function which should only return accessories.
I also noticed something, make sure you are finding the accessories within a ServerScript, The code will unfortunately not run when using a ClientScript.
I started testing out some test code that detects the accessories in a ServerScript, and it seems to be working fine.
I’ve been using a Server script. As for now this is what my code looks like and it’s only deleting the hair?
local char = script.Parent
wait(6)
for _,acc in pairs(char:GetChildren()) do
if acc:IsA("Accoutrement") then
print("2")
if acc.AccessoryType ~= Enum.AccessoryType.Hair then
print("3")
else
acc:Destroy()
print("4")
end
end
end
local char = script.Parent
--Server Script in StarterCharacterScripts
char.ChildAdded:Connect(function(c)
if c.ClassName=="Hat" or c.ClassName=="Accessory" then
c:Destroy()
end
end)
I still don’t know the exact issue but I got it fixed.
local char = script.Parent
wait(6)
for _,acc in pairs(char:GetChildren()) do
if acc:IsA("Accoutrement") then
if acc.AccessoryType ~= Enum.AccessoryType.Hair then
acc:Destroy()
end
end
end