Rocket not on same physics plane and failing check?

I have a bazooka i’m making and I have the rockets on a collision group set to false, so I assume they shouldn’t invoke a .touched event and even with that i have a check on the touched even as well with an ignore list with the rockets in them, basically what i’m trying to achieve is to have it only fire/explode the rocket when it touches someone that isn’t the creator and or another rocket.

		creator = game.Workspace:FindFirstChild(p.Name)
		for i,v in pairs(creator:GetChildren()) do
			if v:IsA("BasePart") then
				ps:SetPartCollisionGroup(v,"creator")
			end
		end
		ps:SetPartCollisionGroup(rocket,"rockets")
		ps:CollisionGroupSetCollidable("creator","rockets",false)
		ps:CollisionGroupSetCollidable("rockets","rockets",false)


rocket.Touched:Connect(function(h)
	if rocket and h then
		if ignorelist[string.lower(h.Name)] then
			return
		end
		if h.Parent.Name == p.Name or h.Parent.Parent.Name == p.Name then
			return
		end
		local explosion = Instance.new('Explosion')
		
		explosion.BlastPressure = 0
		explosion.BlastRadius = 1
		explosion.ExplosionType = Enum.ExplosionType.NoCraters
		explosion.Position = rocket.Position
		explosion.Parent = game.Workspace
		explosion.Hit:connect(function(hit) 
			if hit then
				if hit.Parent:FindFirstChild("Humanoid") then
					if hit.Parent.Name == p.Name then
						return
					else
						addtags(hit.Parent.Humanoid)
					end
				end
				if hit.Parent.Parent:FindFirstChild("Humanoid") then
					if p.Parent.Parent.Name == p.Name  then
						return
					else
						addtags(hit.Parent.Parent.Humanoid)
					end
				end
			end
		end)
	end
	rocket:Destroy()
end)
3 Likes

When you bind a function to the Touched event, you have one argument which you can use, and it is always the Part that called the event. You could use that to check if the part that touched the Rocket is the owner or another rocket, somewhat like this:

Rocket.Touched:Connect(function(Hit)
 if Hit:IsDescendantOf(workspace.Rockets) then
  -- It is another rocket
 elseif Hit:IsDescendantOf(OwnerCharacter) then
  -- It is the character of the owner
 end
end)

Of course you need to modify the code so it works with the code you gave above.

1 Like

Thank you, that worked perfectly!

1 Like