I am making a few morphs and only need to keep the head accessories. I have a basic script that removes accessories but I am wondering how I make it keep only the accessories located on the head.
local d = hit.Parent:GetChildren()
for i=1, #d do
if (d[i].className == "Accessory") then
d[i]:remove()
end
end
end
script.Parent.Touched:connect(onTouched)
although some ugc creators have not properly defined their own accessory type
but you can still identify them by their attachments
try
local function onTouched(hit)
local Humanoid = hit.Parent:FindFirstChildWhichIsA("Humanoid")
if Humanoid then
for _, Accessory in pairs(Humanoid:GetAccessories()) do
local Handle = Accessory:FindFirstChild("Handle")
if Handle then
local Attachment = Handle:FindFirstChildWhichIsA("Attachment")
if Attachment and Attachment.Name:match("Hat") or Attachment.Name:match("Hair") or Attachment.Name:match("Face") then
return
else
Accessory:Destroy()
end
end
end
end
end
script.Parent.Touched:Connect(onTouched)
local players = game:GetService("Players")
local function onPlayerAdded(player)
local function onCharacterAdded(character)
if not player:HasAppearanceLoaded() then
player.CharacterAppearanceLoaded:Wait()
end
for _, accessory in ipairs(character:GetChildren()) do
if accessory:IsA("Accessory") then
if accessory.AccessoryType.Value >= 3 or accessory.AccessoryType.Value <= 7 then
accessory:Destroy()
end
end
end
end
player.CharacterAdded:Connect(onCharacterAdded)
end
players.PlayerAdded:Connect(onPlayerAdded)
This works, you may need to change the 3 & 7 values to blacklist/whitelist certain accessory types, you can check the AccessoryType enumerations here.