Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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)

3 comments

0

replace face? bla with FaceAttachment or whatever the attachment is called, i myself don't have face accessories to test (=

0

Or you can just iterate Character:GetDescendants() and check if its name is "HairAttachment", etc.

0

It is shorter than that B)

This discussion is preserved as it was. New answers, comments, and votes are closed.