This question already has an answer here:

I've seen a lot of tutorials for detecting the player at certain X,Y,Z coordinates, but I want to detect only the player's Y coordinate. In this situation I want to detect the player at Y level 18. I tried things like execute if entity @a[y=18.5,distance=1.5] but that doesn't work. execute if entity @a[x=~,y=18.5,z=~,distance=1.5] doesn't work either. Do I need different commands?

marked as duplicate by Fabian Röling, Virusbomb, Ivo Coumans, arghtype, Schism Nov 1 '18 at 5:28

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • ⬆️ Just leave out the execute part from that answer. – Fabian Röling Oct 31 '18 at 10:16

You don't need to specify x and z, so you want something like

execute if entity @a[y=18] run yourcommand

Or if you want to detect players between 18 and 19, use

execute if entity @a[y=18..19] run yourcommand

Not the answer you're looking for? Browse other questions tagged or ask your own question.