Usually, it’s due to a poor internet connection, incorrect date and time, VPN, old update version, and Apple server issues that make you stick with this message there was an error connecting to the apple id server.