Why is this not working?

I am attempting to create a system that destroys parts if they do not have a certain name. Here is my system:

for i,v in pairs(parts) do
			local function hit(part)
				if time ~= 0 then
					if part.Name ~= "Plate" or part.Name ~= "terrain" then
						print(part.Name)
						part:Destroy()
						return
					end
				end
			end
			
			v.Touched:Connect(hit)
		end

However, when the script runs, here is the result:

image

And if you look back at my code, I only ask for part names to be printed if they are to be destroyed. You have also probably guessed those parts were destroyed.

I don’t get how this isn’t working, help!

if part.Name ~= "Plate" and part.Name ~= "terrain" then

Enjoy.

2 Likes

Wow, it works! I thought you’d have to put ā€œorā€ and not ā€œandā€ since a part can’t have both names at once as ā€œandā€ would imply. Thank you though!

Usually that is correct, but when reading conditions it is read in a slightly different way:
ā€œIf the parts name isn’t ā€˜Plate’, and it also isn’t ā€˜terrain’ then:ā€

Hopefully this helps you in the future!

2 Likes

Ah, I see. Thank you very much!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.