How do I check if a part is part of ANY player?

Basically, say I have a variable pointing to a player’s foot. How could I quickly check if that foot belongs to a player?

Do you want to include only limbs (ie arms, torso, head…)?

If so, check if players:GetPlayerByCharacter(var.Parent) is nil. If it isn’t nil, it belongs to a player and is a limb.

Do you want to include accessories and everything above?
If so, check if players:GetPlayerByCharacter(var:FindFirstAncestorWhichIsA('Model')), if not nil, belongs to a player.

Do you want to include tools and everything above?
If so, check if players:GetPlayerByCharacter(var:FindFirstAncestorOfClass('Model')) again, if not nil, belongs to player. Because tools now inherit models using :FindFirstAncestorWhichIsA(‘Model’) will return the actual tool instance, not the character.

6 Likes

if Foot.Parent:FindFirstChild(“Humanoid”) then

end

if part.Parent:FindFirstChildWhichIsA("Humanoid") then
    print('oi')
end

Exercitus and Pleb those will trigger with any humanoid which is not preferable for me

1 Like

just use players:GetPlayerByCharacter()

1 Like

Use foot:IsDescendantOf(characterModel)

The best method to get the player from any descendant of the character (including nested models, accessories and tool handles) would be to recursively find the second to last Model and plug it in with GetPlayerFromCharacter.

local function GetPlayerFromDescendant(Descendant: Instance): Player?
	local Model: Model? = Descendant:FindFirstAncestorWhichIsA("Model")
	
	while Model and Model.Parent and Model.Parent:IsA("Model") and Model.Parent ~= workspace do
		Model = Model.Parent
	end
	
	return Players:GetPlayerFromCharacter(Model)
end
2 Likes