Why is my function removing items from the Folders it's told not to remove items from?

Achieve

I’m attempting to make a button that removes all the children from certain folders.

Issue

My issue is that this function I made removes items from the folders I tell it not to remove items from

Solutions

I’ve tried using the not function, using the parents’ name, using the does not equal sign, I’ve tried moving where the check lies., and so on.

Function

local function RemoveMatches(plr)
	local Matchtypes = game:GetService("Workspace").Matchtypes
	for _,Folder in pairs (Matchtypes:GetChildren()) do
		if Folder.Name ~= "Stages" or Folder.Name ~= "Rings & Extras" or Folder.Name ~= "Main Items" then
			for x,Matchtype in pairs (Folder:GetChildren()) do
				if Matchtype then
					Matchtype:Destroy()
					print("Matches Removed.")
				end
			end
		end
	end
end

Thank you for any help you can give me.

You’re doing the opposite. You want to use and.

1 Like

use and instead of or in line 4

if Folder.Name ~= "Stages" and Folder.Name ~= "Rings & Extras" and Folder.Name ~= "Main Items" then

This would also work, according to DeMorgan’s law:

if not (Folder.Name == "Stages" or Folder.Name == "Rings & Extras" or Folder.Name == "Main Items") then
1 Like