Part.touched not detecting the child of another parts parent

Im trying to detect humanoids and subtract health from them but it can detect multiple children of the model and I don’t know how to make sure it finds the player’s model and then the Humanoid within it

this is the code

tool = script.Parent

boomsize = 6
boommax  = 150


tool.Activated:Connect(function()
	local grenade = game.ReplicatedStorage.grenade:Clone()
	grenade.Position = tool.boom.Position
	grenade.Orientation = tool.boom.Orientation
	grenade.Parent = workspace
	wait(.3)
	grenade.VectorForce:Destroy()
wait(.3)
	grenade.Touched:Connect(function()
		local kablooey = Instance.new("Part")
		kablooey.Shape = Enum.PartType.Ball
		kablooey.CanCollide = false
		kablooey.Anchored = true
		kablooey.Size = Vector3.new(boomsize,boomsize,boomsize)
		kablooey.Position = grenade.Position
		kablooey.Parent = workspace

--this is the problematic part
		kablooey.Touched:Connect(function(targ)
			
			print(targ)
			if  targ.Parent:FindFirstChild("Humanoid") then
				if targ:IsA("Humanoid") then
					targ.Humanoid.Health -=boommax
				end
				
				
			end
		end)
		grenade:Destroy()
	end
		)
	
end)

it detects handles of accessories and body parts so i must be able to find the player model and then the humanoid

1 Like

Hello, i am on phone, but try this:

—code at start of script
function getHuman(part)
local model = part:FindFirstAncestorOfClass(“Model”)
if model then
local human = model:FindFirstChildOfClass(“Humanoid”)
if human then
return human
end
end
end

—code at the kaboom part
local human = getHuman(targ)
if human then
—code
end

1 Like

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