I've recently had some difficulties finishing a system; in fact, I need to /testfor myself if I'm on spectator mode or another gamemode. Because I didn't know what to write, I tried this, but it didn't work:

/testfor Kimatuy {gamemode:3}

Can you help me with this?

  • 5
    Try this: /testfor @p[name=Kimatuy, m=3]
    – Tom Shen
    Commented May 11, 2016 at 12:49
  • 1
    If anytimothy's answer solved it, you should hit the check mark :)
    – APCoding
    Commented May 11, 2016 at 23:25

2 Answers 2


Instead of testing for a gamemode NBT tag, why don't you use the gamemode selector instead?

/execute if entity @a[gamemode=adventure]

If you want to mark players, you can use a /scoreboard command with the selectors set to @a[gamemode=adventure].

Before 1.13, it is /testfor @a[m=2], but as of 1.13, m was renamed to gamemode, /testfor was renamed to /execute if entity, and the argument is now the name of the mode.

Props to @ppperry for notifying me of this.

  • 1
    m was renamed to gamemode in 1.13
    – pppery
    Commented Aug 11, 2018 at 18:26
  • @ppperry Submit a suggested edit or create a new answer so that you can receive credit.
    – aytimothy
    Commented Aug 11, 2018 at 19:46
  • May I point out that your answer before the edit was testing for players in spectator mode, but your edit used adventure mode?
    – pppery
    Commented Aug 11, 2018 at 20:15
  • Also, /testfor no longer exists in 1.13; it was merged into /execute as /execute if entity [selector]
    – pppery
    Commented Aug 11, 2018 at 20:33

To complete what aytimothy said, `@a[m=M] targets all Players with gamemode M:

0 for Survival, 1 for Creative, 2 for Adventure, 3 for Spectator. For targeting Players that are, fer example, in gamemode 0 or 2, use scoreboards (vis my answer):

First, create a dummy scoreboard objective:

/scoreboard objectives add gameM dummy  

Then, add all Players with gamemode Survival and Adventure to the "selectMe":

/scoreboard players set @e[m=0] gameM 1  
/scoreboard players set @e[m=2] gameM 1  

Now you can enter your command:

/testfor @a[score_gameM_min=1,r=15]  
  • 3
    tags are better than scoreboards for this.
    – MrLemon
    Commented May 11, 2016 at 18:03
  • 2
    @RudolfJelínek "Tags" are a new feature added in 1.9 to add a label to a target without the use of objectives. It's much more efficient both internally and with command mechanisms where you need to target an entity based on a true/false condition.
    – Skylinerw
    Commented May 11, 2016 at 18:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .