How to check if a part is a descendant of an object with a humanoid parented to it

Basically I need to check for a part that is a descendant of a model with a humanoid parented to said model for a damage function that my gun system uses because the bullets are being caught on hats and armor preventing the damage from working.

Any help is appreciated.

if Part:IsDescendantOf(Character) then

Can’t get the character because it registers the part that I need to check

Something such as this?

if part:FindFirstAncestorOfClass("Model") then -- getting the first ancestor that is a Model
    local char = part:FindFirstAncestorOfClass("Model")
    if char:FindFirstChildOfClass("Humanoid") then -- checking if a Humanoid exists in said ancestor
        -- code here
    end
end

No, that wouldnt work because the armor is parented to a model.

Alright, I fixed it myself. For anyone coming to this for an answer, here you go:

local hitPart = workspace.examplepart
local fullpath = hitPart:GetFullName()
local names = string.split(fullpath,".")
local humanoid = game.Workspace[names[2]]:FindFirstChildOfClass("Humanoid")

5/17/24 edit:
you can also just disable query on armor parts if you’re using raycasts (i believe? havent tested) or exclude anything with an armor tag (update exclude table accordingly to armor removal or addition)

2 Likes

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