Quick way to get Humanoid from a Touched event?

Whenever i need to get a Humanoid from a Touched event, i need to always do something like this before i can do the function i wanted to do:

script.Parent.Touched:Connect(function(h)
	if h.Parent:IsA("Model") then
		if h.Parent:FindFirstChildWhichIsA("Humanoid") then
			--function
		end
	elseif h.Parent:IsA("Accessory") then
		if h.Parent.Parent:FindFirstChildWhichIsA("Humanoid") then
			--function
		end
	end
end)

Is there a way of shortening this for saving time?

Before replying, i have tried:
-:FindFirstAncestorWhichIsA("Humanoid") Doesn’t work, as the Accessory nor the limb part are descendants of the Humanoid.

That’s just about as close as you can get to retrieving a humanoid from Touched event.
Although you could slightly simplify it even further by skipping straight to

local Humanoid = h.Parent:FindFirstChild("Humanoid")
if Humanoid then
--
end
1 Like

Thanks, but i have now found a better way to simplify it, but thanks!

For anyone that wants to know, it’s:

if h:FindFirstAncestorWhichIsA("Model") then
    local model = h:FindFirstAncestorWhichIsA("Model")
    if model:FindFirstChildWhichIsA("Humanoid") then
        local hum = model:FindFirstChildWhichIsA("Humanoid")
    end
end