The text is an idiomatic expression advising that if one cannot behave in a morally good way, they should at least avoid getting into trouble. It does not play on different meanings of a word or similar-sounding words.
If you can ' t be good , be careful .