As someone who has been through the criminal justice system a handful of times, here's what I always tell people:
If you are approached by a policeman/woman, you don't need to say anything other than, "I'm going to ask you to refer all questions to my counsel as I'm not prepared to handle or able to answer any questions you may have."
Don't have counsel? Get some. Can't afford any? Tell the policeman/woman that you'll "confer with your legal team" and if your "legal team" believes it's appropriate to answer questions, you'll let them know. Oh, and call your local public defender's office.
A policeman/woman may, "just want to talk" or, "ask you a few questions"; that's okay, just repeat what you said. They may say "you're not in trouble" and that's great, so repeat what you said.
A policeman/woman can only get you in trouble, they cannot get you out of trouble.
When it comes to court, our public defenders system, while it means well, is horribly broken. PDs are often assigned far too many cases they can reasonably handle. PDs don't go to trial often enough, because they can't handle the additional workload.