Hello, I was working on a project that includes a script where I remove ALL accessories EXCLUDING HairAttachments but I wanted to add Face and Hat attachments as well and leave out the rest to be destroyed. Here is the script for anyone who is willing to help!
01 | local Players = game:GetService( "Players" ) |
02 |
03 | function PlayerAdded(Player) |
04 | Player.CharacterAppearanceLoaded:Connect( function (Character) |
05 | local parts = Character:GetChildren() |
06 | for i = 1 , #parts do |
07 | local instanceA = parts [ i ] |
08 | if (instanceA.ClassName = = "Accessory" ) then |
09 | if not instanceA.Handle:FindFirstChild( "HairAttachment" ) then |
10 | parts [ i ] :Destroy() |
11 | end |
12 | end |
13 | end |
14 | end ) |
15 | end |
16 |
17 |
18 | Players.PlayerAdded:Connect(PlayerAdded) |
You can use and not to chain multiple conditions. Also I used modern way of looping, not your for i = 1, 10, dude it's not 2015, it's not 2020, it's 2023!!!!! )=<
01 | local Players = game:GetService( "Players" ) |
02 |
03 | function PlayerAdded(Player) |
04 | Player.CharacterAppearanceLoaded:Connect( function (Character) |
05 | for _, instance in Character:GetChildren() do |
06 | if instance:IsA( "Accessory" ) then |
07 | if not instance.Handle:FindFirstChild( "HairAttachment" ) |
08 | and not instance.Handle:FindFirstChild( "HatAttachment" ) |
09 | and not instance.Handle:FindFirstChild( "face? bla" ) then |
10 | instance:Destroy() |
11 | end |
12 | end |
13 | end |
14 | end ) |
15 | end |
16 |
17 | Players.PlayerAdded:Connect(PlayerAdded) |