How to update an image attachment’s alt text from a custom field when saving a post?

I found the problem. It was updating the post instead of the attachment. So instead of $post->ID, I create another string that stores the image ID and replace that with post->ID and it works.

function post_extra_save( $post_id, $post){
if ( has_blocks( $post->post_content ) ) {
$blocks = parse_blocks( $post->post_content );
foreach ( $blocks as $block ) {
    if ( $block['blockName'] === 'acf/opby-cover-image' ) { // name of block
        $media_url_thumb = $block['attrs']['data']['image_post']; // Image ID from the block 
        $cover_img_photo_alt = $block['attrs']['data']['photo_alt_text']; // text field for `photo_alt_text`

        update_post_meta($media_url_thumb, '_wp_attachment_image_alt', $cover_img_photo_alt);
    }
}
};
}
add_action( 'save_post', 'post_extra_save', 10, 2 );