This Story is adapted from How to Change: The Science of Getting from Where You Are to Where You Want to Be by Katy Milkman.

When you walk 10,000 steps in a day, your Fitbit rewards you with a jiggle and some virtual fireworks, giving you a reason to pause and smile with pride. When you practice a foreign language on Duolingo multiple days in a row, you earn a “streak” and are encouraged to maintain it, giving you an extra reason to strive for repetition. When companies, teachers, coaches, or apps add features such as symbolic rewards, competition, social connections, or even just fun sounds and colors to make something feel more like play, they’re relying on “gamification” to enhance an experience that might otherwise be dull. I’d wager that most of the apps on your phone use some element of gamification, but we also see gamification in our workplaces and from our health insurers.

Gamification first took off more than a decade ago. At the time, there wasn’t much evidence for its value; the concept just seemed to make sense. Business consultants promised organizations that gamifying work could more effectively motivate employees, not by changing their work itself, but by changing its packaging, and making goal achievement a bit more exciting as a result (“Yes! I earned a star!”). Technology companies like Cisco, Microsoft, and SAP, for instance, found ways to gamify everything from learning social media skills, to verifying language translations, to boosting sales performance.

Today, thanks to science, we know a lot more about when gamification really works, and what its boundaries seem to be. Beyond the gamified apps and software we use to learn new skills, companies like Amazon and Uber now deploy it to boost worker productivity. But to get the results we seek, in our own lives and in the workplace, it’s important to understand when gamification will work—and when it will only make matters worse.

In 2012, Jana Gallus, a brilliant young economist studying for her doctorate at the University of Zurich, learned of a problem plaguing Wikipedia—and saw an opportunity to run an early test of the value of gamification. Despite the popularity of the 50-million-entry online encyclopedia available in over 280 languages, Gallus discovered that its top performing editors were leaving in droves. And since the so-called Wikipedians who keep the site’s articles on everything from Game of Thrones to quantum mechanics accurate and up to date don’t get paid a dime, the organization needed to find a way to keep its top editors engaged with the sometimes-monotonous task of curating online content without offering them money.

In the hopes of reducing turnover, Wikipedia let Gallus run an experiment with 4,000 new volunteer editors. Based on the flip of a coin, she told some deserving Wikipedia newcomers that they had earned an accolade for their efforts, and their names were listed as award winners on a Wikipedia website. They also received either one, two, or three stars, which appeared next to their username, with more stars allocated to better performers. Other newcomers who had contributed equally valuable content to Wikipedia but came out on the other end of the coin flip got no symbolic awards (and weren’t told that such awards existed). Gallus thought the awards would make a monotonous task feel a bit more like a game by adding an element of fun and praise for a job well done.

She was right. The volunteers who received recognition for their efforts were 20 percent more likely to volunteer for Wikipedia again in the following month and 13 percent more likely than those who earned no praise to be active on Wikipedia a year later.

Examples like this one might make gamification seem like a no-brainer: Why wouldn’t a corporation want to make work more fun? Despite Gallus’ exciting results, more recent research shows that as a top-down strategy for behavior change, gamification can easily backfire. Two of my Wharton colleagues—Ethan Mollick and Nancy Rothbard—ran an experiment that proved just that. It involved several hundred salespeople who had the somewhat boring job of reaching out to businesses and convincing them to offer coupons for discounted products or services that were then sold on their company’s website (think Groupon). The salespeople earned commissions for each coupon eventually sold online.

In an attempt to make this more exciting, Mollick and Rothbard worked with professional game designers to create a basketball-themed sales game. Salespeople could earn points by closing deals with customers, with more points awarded for bigger deals. Sales from warm leads were called “layups,” while cold calls were dubbed “jump shots.” Giant screens on the sales floor displayed the names of top performers and showed occasional basketball animations like a successful dunk. Regular emails updated the “players” on who was winning, and when the game was over, the winner got a bottle of champagne.