Detect if the player is at a specific y level in 1.14

Detect if the player is at a specific y level in 1.14 - Young Man resting his Arm on a Basketball

I am in 1.14 and I want to check if the player is at a specific Y value.

I tried /execute at @a[y=10] run say hi but for some reason, this will constantly return true no matter what.

I tried /execute at @a[y=10,distance..2] run say hi but this will only work if the player's X and Y values match the command blocks.

How do I detect if the player is at a specific Y value/level?



Best Answer

You can use this code:

/execute as <player you want to check> at @s if entity @s[y=65,dy=0] run say hi

It will say hi if the hitbox of the player is within the block at y=65. the dy=0 appears to be nessessary to prevent it from always saying hi, the x and z seem to default to the position where the command is executed.

This would probably work, too:

/execute at <player you want to check> if entity @p[y=65,dy=0] run say hi



Pictures about "Detect if the player is at a specific y level in 1.14"

Detect if the player is at a specific y level in 1.14 - Ground level of cheerful woman and crop curler with curling brooms sweeping ice sheet in front of rock during training on rink
Detect if the player is at a specific y level in 1.14 - A Shuttlecock on the Badminton Court
Detect if the player is at a specific y level in 1.14 - Free stock photo of active, athlete, ball



How do you see what level your player is in Minecraft?

You can test for player's levels using the l= or lm= arguments in the target selector.

How do you test a player in Minecraft in a certain area?

2. Type the Command
  • Test if Players are within 10 blocks. In this example, we will test to see if there are any players within a 10 block radius with the following command: /testfor @a[r=10] ...
  • Test if Mooshrooms are within 50 blocks. ...
  • Test if Nearest Player is at Level 20 experience.




  • [Tutorial] Detect SNEAKING in Minecraft




    More answers regarding detect if the player is at a specific y level in 1.14

    Answer 2

    I found the next 1 line command to be working. First, execute as all players, then as all players that are at y=10 with dy=0.

    /execute as @p as @s[y=10,dy=0] run tellraw @s "Test"
    

    One thing I found is that y seems to be where any part of the player is.

    Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.

    Images: RODNAE Productions, SHVETS production, SHVETS production, cottonbro