What do you do when you’re playing and totally lose your swing?

Today I was playing and I could barely hit the ball. I’m an 18 so I typically keep the ball moving pretty well, but miss greens and make a lot of bogeys. Today I kept topping the ball. It was driving me crazy.

I don’t expect you guys to know what I was doing wrong without seeing me, but what are some general tricks you guys have developed for getting yourself back on track when something has gone really wrong with your swing and your confidence is shot?