Mask remove script edit?

So I made this mask script a while back and it transparency’s hair and when you take it off, it untransparencys it, but I have some hair that the handle isn’t supposed to untransparency the handle, only the child of it, which as an example of this bun. So how do I make it skip over bun and else. How would I do this?

local re = script.Parent.RemoveMask

re.OnServerEvent:Connect(function(player)
	local character = player.Character
			wait(1)
			local d = character:GetChildren()
			for i=1, #d do
				if (d[i].className == "Accessory") and (d[i].Name == "Bun") then
					d[i].Handle.Transparency = 1
					local f = d[i].Handle:GetChildren()
			        for i=1, #f do
					if f[i].Name == "Prop" then
					f[i].Transparency = 0
					else
					d[i].Handle.Transparency = 0 
					local f = d[i].Handle:GetChildren()
			        for i=1, #f do
					if f[i].Name == "Prop" then
					f[i].Transparency = 0
				end
				end
				end
					end
			end
				end
character.MaskForHide:Destroy()
				local dog = character.BlackMask or player.Backpack.BlackMask
				character.Head.Hidden.Enabled = false
				character.Head.Title.Enabled = true
				dog.Handle.Transparency = 0
			end)

Instead of saying

for i = 1, #f do

you could say something like,

for i,v in pairs(f) do
   if v.Name == "Prop" then
         v.Transparency = 0
   end
end

For the functions. I’m not sure if this solves your issue (as I wasn’t quite able to understand your issue from what you posted) but this should help to some extent.

Make a table that stores the assetId of the hats or any other information that distinguishes it from others.

local table = {
information
information
}

then you want to make a for loop through the character.

You could either do numberic (fastest option) or for _, v or for i, v or whatever you are comfortable with.

local table = {
information
information
information
}

local child = character:GetChildren()
for i = 1, #child do
	if child[i]:IsA("Accessory") then
		if child[i] == table[i] then
			return
		else
			child[i].Transparency = 1
		end
	end
end