Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would I exclude Hair, Hat, and Face attachments from removal?

Asked by 2 years ago
Edited by imKirda 2 years ago

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!

01local Players = game:GetService("Players")
02 
03function 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)
15end
16 
17 
18Players.PlayerAdded:Connect(PlayerAdded)

1 answer

Log in to vote
1
Answered by
imKirda 4491 Moderation Voter Community Moderator
2 years ago

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!!!!! )=<

01local Players = game:GetService("Players")
02 
03function 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)
15end
16 
17Players.PlayerAdded:Connect(PlayerAdded)
0
replace face? bla with FaceAttachment or whatever the attachment is called, i myself don't have face accessories to test (= imKirda 4491 — 2y
0
Or you can just iterate Character:GetDescendants() and check if its name is "HairAttachment", etc. T3_MasterGamer 2189 — 2y
0
It is shorter than that B) T3_MasterGamer 2189 — 2y
Ad

Answer this question