I think that in order to use the coordinate selectors in a command, you have to use the "@a" selector instead of the "@p".
I think that in order to use the coordinate selectors in a command, you have to use the "@a" selector instead of the "@p".