Get the closest limb facing player

How would I go by this? using magnitude of course I tried already and It just keeps returning nil, here is my code.

function lib.GetClosestLimb(r, what)
	local range = r
	local limbs = {}
	local position = plr.Character.PrimaryPart.Position
	position += plr.Character.PrimaryPart.CFrame.LookVector * range/2
	for i, limb in ipairs(what:GetChildren()) do
		if (limb.Parent.PrimaryPart.Position - position).magnitude > range/2 then continue end
		table.insert(limbs, limb)
	end
	return limbs
end

I am a little confused at what you are trying to achieve here and what r and what are.

Try using raycast and if the ray gets hit and detects a player limb, do whatever.