What does "keeps failing" mean, exactly? Fails how? Fails to connect? Fails to play? Hard to fix "it doesn't work" without more information.
Also, what car, what system? BT, which is the connection for CarPlay, is really dodgy in some (many) cars and is the number one cause of issues.
CarPlay is all wired and not wireless through BT or otherwise. I believe there are a number of 3rd party solutions that allows you to go wireless, but a late model car doesn't have that.
My SUV has CarPlay support and in 95% of the cases it works when I plug my iPhone in. Once in a while I get a message indicating "The USB connection has failed, disconnect and reconnect.." or something to that effect. However, disconnecting and reconnecting doesn't do anything and CarPlay will not work for that entire duration.
The next time I turn off the car and turn it back on, it almost always works.
If re-connecting the phone freshly doesn't make the connection reliable, you're unfortunately just dealing with the early instance of CarPlay in cars that might be buggy.
Realize that based on your cars age, the electronics in there are usually 3-5 years older.