How can I delete items through a loop but ignore some

So whenever a player joins I add a frame into tdmboard
image

I want to keep the local script and all the templates but I end up just deleting all the children
image
Picture of everything i want to keep

If they are not in the picture I want to delete it

for _,v in pairs(tdmboardGui:GetChildren()) do 
	if not v:IsA("LocalScript") then 
		if not v == "BlueKill" or not v == "RedKill" or not v == "BlueTemplate" or not v == "RedTemplate" then 
			v:Destroy()
		end
	end 
end

You’re comparing the frame object to a string. You need to do:

if v.Name ~= "BlueKill"  then -- make sure to add all your other conditions.

Also you may want to use “and” instead of “or” statements because if the first condition is met, it will just ignore the others.

4 Likes

Thanks I will try this


	for _,v in pairs(tdmboardGui:GetChildren()) do 
		if not v:IsA("LocalScript") then 
			if v.Name ~= "BlueKill" and v.Name ~= "RedKill" and v.Name ~= "RedTemplate" and v.Name ~= "BlueTemplate" then 
				v:Destroy()
			end
		end 
	end