Touched Event Problem

Hello

I’ve got this code here

Missile.Payload.Touched:Connect(function(HitPart)

		if HitPart.Name ~= 'Payload' or HitPart.Name ~= 'Engine1' then
			if HitPart.Parent:FindFirstChild('Humanoid') then
				local Plr = game.Players:GetPlayerFromCharacter(HitPart.Parent)
				Plr.Character.Humanoid:TakeDamage(100)
			elseif HitPart.Parent.Parent.Name ~= 'BodyKit' or HitPart.Parent.Parent.Parent.Name ~= 'BodyKit' or HitPart.Parent.Parent.Parent.Parent.Name ~= 'BodyKit' or HitPart.Parent.Parent.Parent.Parent.Parent.Name ~= 'BodyKit' then
				print(HitPart.Parent.Parent.Name)
				CreateExplosion(HitPart.Position, 20)
				CreateTag(HitPart)
				Missile:Destroy()
			end

		end

	end)

This code here is for some reason running even though the HitPart.Parent.Parent.Name prints out BodyKit.
I’m very confused right now and I appreciate any help I can get. Thanks!

1 Like

Hi!

Not sure if that makes a difference, have you tried using
elseif HitPart.Parent.Parent.Name ~= "BodyKit"?
Maybe it’s trying to compare a string (") with a character ('). Not sure if I am right, though, since I don’t do Lua a lot :wink:

1 Like

It’s because:
Hit.Parent.Parent.Name is BodyKit
Hit.Parent.Parent.Parent.Name isnt BodyKit
you put OR so only one of the conditions must be respected to execute the code

2 Likes

@davidemba Hi!
I switched it, and the problem is still the same.

you must put AND instead of OR

2 Likes

Ah, look, I didn’t even look at the ‘or’ statements! Yes, your answer is most likely the correct one!

@Lap_124 Thank you! I didn’t realise that.

1 Like