Help with Descendants and Accessories

I am trying to make so that when you click a button, it will remove certain accessories from a character (MainAvatar)

So basically, it removes all the accessories

local character = game.Workspace.Character.MainAvatar
local humanoid = character.Humanoid

	local decentdants = character:GetDescendants()
	for _, descentant in pairs(decentdants) do
		if descentant:IsA("Accessory") then
			if == "ModularPlateCarrierAccessory" or "ModularPouchesAccessory" then

comment to get to the top of the list

In Lua, the logical operator “or” is generally used to determine whether either of the conditions passed is equivalent to true. If the first condition is true, it will return true as well. Conversely, if the operator is “and” and the condition is true, it will attempt to glance at each subsequent condition.

print(false and true) -- false
print(true and false) -- false
print(false or true) -- true
print(true or false) -- true

As for the code, the second if statement might be confusing consequently. It checks whether the descendant’s name is “ModularPlateCarrierAccessory”; otherwise, the second argument. However, the second argument always returns true for the if statement because it is recognized by the engine as if that is a single string. Therefore, you would use another or statement that connects both equal to operators.

if ( == "ModularPlateCarrierAccessory") or ( == "ModularPouchesAccessory") then
1 Like

name is deprecated, use Name instead.