Before you do the update_field. If you output $value, does it return anything?
Have you tried adding the post ID to the update_field to see if that works?
update_field($field_key, $value, $element->ID);
I assume the closing tag for the foreach isn’t included in the above code?