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 1 year ago
Edited by imKirda 1 year 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!

local Players = game:GetService("Players")

function PlayerAdded(Player)
    Player.CharacterAppearanceLoaded:Connect(function(Character)
        local parts = Character:GetChildren()
        for i = 1, #parts do
            local instanceA = parts[i]
            if (instanceA.ClassName == "Accessory") then
                if not instanceA.Handle:FindFirstChild("HairAttachment") then
                    parts[i]:Destroy()
                end
            end
        end
    end)
end


Players.PlayerAdded:Connect(PlayerAdded)

1 answer

Log in to vote
1
Answered by
imKirda 4491 Moderation Voter Community Moderator
1 year 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!!!!! )=<

local Players = game:GetService("Players")

function PlayerAdded(Player)
    Player.CharacterAppearanceLoaded:Connect(function(Character)
        for _, instance in Character:GetChildren() do
            if instance:IsA("Accessory") then
                if not instance.Handle:FindFirstChild("HairAttachment")
                and not instance.Handle:FindFirstChild("HatAttachment")
                and not instance.Handle:FindFirstChild("face? bla") then
                    instance:Destroy()
                end
            end
        end
    end)
end

Players.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 — 1y
0
Or you can just iterate Character:GetDescendants() and check if its name is "HairAttachment", etc. T3_MasterGamer 2189 — 1y
0
It is shorter than that B) T3_MasterGamer 2189 — 1y
Ad

Answer this question