Touched function will only detect parts inside player?

my touched function will only detect parts inside player:


rocket = Instance.new("Part", workspace)
		rocket.Size = Vector3.new(1,1,20)
		rocket.Anchored = true
		rocket.CanCollide = false
		rocket.Position = char.PrimaryPart.Position + char.PrimaryPart.CFrame.LookVector * 10
		rocket.CFrame = CFrame.new(rocket.Position, char.PrimaryPart.Position)

rocket.Touched:Connect(function(z)
			print(z.Name)
		--[[	if z.Name ~= "Torso" then
				if z.Name ~= "Head" then
					if z.Name ~= "Left Arm" then
						if z.Name ~= "Right Arm" then
							if z.Name ~= "Right Leg" then
								if z.Name ~= "Left Leg" then
									if z.Name ~= "HumanoidRootPart" then
										rocket:Destroy()
									end
								end
							end
						end
					end
				end
			end]]
		end)

the touched part is the part in the middle*

1 Like

Ok first off, why are you using so many if statements? And what part is not allowing the rocket to destroy?

I dont want it to count the parts in the player as parts to be touched

Okay, and what parts do you want to be counted?

anything other than the parts inside the player

rocket.Touched:Connect(function(z)
			print(z.Name)
if v.Parent:FindFirstChild("Humanoid") then return end
			rocket:Destroy()
		end)

How about this?

Way better logic and is also workable for the different body types. Something that was never considered.

it still detects the players parts like “humanoidrootpart” and “torso”, my problem is that it wont detect any other parts, like “baseplate” or just any random part laying around

Well, where is HumanoidRootPart and torso located? If they are located inside the character, this should work.

Basic code to ignore bodypart touches.

part.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") or hit.Parent.Parent:FindFirstChild("Humanoid") then return end
-- do your stuff here
end)

inside the player
sdv

Then the code should work, try printing after the if statement to test it.

yes it works… but it doesnt detect anything else

Then you must filter the objects.

I also suggest you using looping trough tables instead of using too much if statements.

I’m not sure that looping through tables will fix anything.

How so? It’s set to go off over anything BUT that part. Did you even try it?

No, just to reduce the amount of wastes in the script.

Yea, I don’t understand what’s going on here.


dosent detect other objects for some reason

is the “rocket” the limb that’s being extended?