If you have selected the return format of ‘file object’, the your code won’t work. Your code expects the value to be an ID.
For example, your code $url = wp_get_attachment_url( $attachment_id ); requires $attachment_id to be an integer. However, if you have selected ‘file object’ as the return setting, this will NOT be an integer!
Please read the docs and debug your code to see what data you have available on each line.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users