How to make a script that when part touches any other part it prints

Hello, I want to make a script. Whenever a part touches any other part (Not humanoid) the script must work. The script is this:

script.Parent.Parent.Hit.Touched:Connect(function(part)
	if part == game.Workspace.Wall then -- I want the script to work for every part not only one
		script.Parent:Destroy()
	end
	
end)

I have already done thank you everyone!

1 Like

Do workspace.Wall, instead.

Should, it be:
Some unlisted things that might help you, in this script.

script.Parent.Parent.Hit.Touched:Connect(function(part)
	workspace.Wall:Destroy()
end)

I want like when it touches any part in workspace the script should work not only when it touches only one part. Thanks :slight_smile:

Oh, then, do this:

script.Parent.Parent.Hit.Touched:Connect(function(part)
	if part == workspace.Wall then -- I want the script to work for every part not only one
		print("The full "..workspace.Wall.Name.." got destroyed.")
		workspace.Wall:Destroy()
	end
end)
script.Parent.Parent.Hit.Touched:Connect(function(part)
	if part.Name == "Wall" then
		part:Destroy()
	end
end)

This Should Work

I 99.997% disagree about your script.

1st, you forgot “then” on “if”, ALWAYS PUT then ON if !!
2nd, Part is for the function has a small letter, so it’s part.
3rd, it’s going to end up with 1 error and 1 warning.

And the worst part about, is that it errors.

1 Like

Maybe try this?

script.Parent.Parent.Hit.Touched:Connect(function(part)
	if not part:FindFirstChild("Humanoid") then
		script.Parent:Destroy()
	end	
end)

I am not too sure if this works though.

Try this

for i, v in pairs(workspace:GetChildren() do
  if v:IsA("Part") then
             v.Touched:Connect(function(hit)
                 if not hit:FindFirstChildWhichIsA("Humanoid") then
                      print("wow")
                end
          end)
     end
end

Maybe try this?

yourPart.Touched:Connect(function(hit)
   if hit:FindFirstChildWhichIsA("Humanoid") then return end
   if hit.Name ~= "Wall" then return end
   yourPart:Destroy()
end)

I have already done thanks for helping, I did it with magnitude