Help with Accessory Checker

Trying to check if a player has an Accessory that isn’t on the head.

--Make certain items transparent
for i, v in pairs(cloned_char:GetChildren()) do
	if v:IsA("Shirt") or v:IsA("Pants") then
		v:Destroy()
	end
		
	if v:IsA("Part") or v:IsA("MeshPart") then
		local int = v
		if int.Name ~= "Head" then
			local stand = int
			stand.Transparency = 1
		end
	end
	
	if v:IsA("Accessory") then
		local accessory = v
		for i, items in pairs(accessory.Handle:GetChildren()) do
			if items.Name ~= "HatAttatchment" or "FaceFrontAttachment" or "HairAttachment" then
				local acc = items.Parent.Parent
				acc:Destroy()
			end
			if items.Name == "BodyBackAttatchment" then
				
			end
		end
	end
end

The part at the end where it says v:Destroy() isn’t actually even running for some reason.

Please help, thanks.

1 Like

Are both of the print functions above and below :Destroy() printing in the output?

Are you sure it isn’t just finding something in one of the other if statements?
If it’s finding a shirt or Pants for example then it will not go through the rest of the elseif statements.

They’re not. That’s why I’m confused.

Wait that’s how it works? Dang. It finds Shirts and MeshParts. Probably why it’s not working.

yeah. You should just use if statements to search for each item separately:

if v:IsA("Shirt") or v:IsA("Pants") then
		v:Destroy()
end		
if v:IsA("Part") or v:IsA("MeshPart") and v.Name ~= "Head" then
		v.Transparency = 1
end		
if v:IsA("Accessory")then
		Part1 = v.Handle.AccessoryWeld.Part1
end		
if v:IsA("Accessory") and Part1 ~= cloned_char.Head then
		print("Arrived")
		v:Destroy()
		print("Moving on")
end
1 Like

It’s running now, but now it’s deleting everything inside of the Viewport even though I have if statements blocking it.

I figured out the solution. The reason why nothing was working was that I was using another if statement when I should be using an elseif statement because they only work if the first option doesn’t fit the criteria.

Here’s the code:

--Make certain items transparent
for i, v in pairs(cloned_char:GetChildren()) do
	if v:IsA("Shirt") or v:IsA("Pants") then
		v:Destroy()
	end
		
	if v:IsA("Part") or v:IsA("MeshPart") then
		local int = v
		if int.Name ~= "Head" then
			local stand = int
			stand.Transparency = 1
		end
	end
	
	if v:IsA("Accessory") then
		local accessory = v
		for i, items in pairs(accessory.Handle:GetChildren()) do
			if items:IsA("Attachment") and items.Name == "HatAttachment" or items.Name == "FaceFrontAttachment" or items.Name == "HairAttachment" then
				local acc = items
				local access = acc.Parent.Parent
				print("Keep: ".. access.Name)
			elseif items:IsA("Attachment") and items.Name ~= "HatAttatchment" and "FaceFrontAttachment" and "HairAttachment" then
				local ax = items
				local axx = ax.Parent.Parent
				axx:Destroy()
			end
		end
	end
end

Thanks to everyone who helped me on this @ZombieCrunchUK @Icey_CD.

1 Like