Minecraft executing on an entity not working

What i am trying to do is make an entity say hi when it is in a certain radius of another entity. I have used a scoreboard called PigProgress. What is happening is that I am giving a score of 1 to every porkchop item dropped. Then when a diamond is dropped next to i want them both to dissappear an then other things to happen.
I have tried this command but it has failed
/execute @e[score_PigProgress_min=1,score=1] ~ ~ ~ /execute @e[type=Item,r=1] {Item:{id:minecraft:diamond}} ~ ~ ~ /say hi
Best Answer
There are two things wrong with your command.
The target selector for the first execute is wrong, although I assume this to be a typo. It should (probably) be
@e[score_PigProgress_min=1,score_PigProgress=1]
although the second part is not really necessary, unless porkchops with a score of 2 are a different thing./execute
does not support matching dataTags, which is what you are attempting in the second execute. You will have to assign a scoreboard value for diamond items, similar to what you did with the porkchops.
Lastly, to achieve what you want, I suggest summoning an invisible Armor Stand to work using the double execute and work from there. I.e.
/execute @e[type=Item,score_PigProgress_min=1] ~ ~ ~ /execute @e[type=Item,score_isDiamond_min=1,r=1] ~ ~ ~ /summon ArmorStand ~ ~ ~ {CustomName:"Marker1",Marker:1b,Invisible:1,Invulnerable:1,NoGravity:1}
This assumes all pork chops and only those have a PigProgress score of 1 or more, and all Diamond Items (and only those) have a isDiamond
score of 1 or more.
Now you can execute everything else (/kill
ing the items, saying "Hi", etc.) from the armor stand using
/execute @e[type=ArmorStand,name=Marker1] ~ ~ ~ <command>
Don't forget to kill the armor stand in the end as well.
Pictures about "Minecraft executing on an entity not working"



How do you execute all entities in Minecraft?
The game processes these subcommands in order from front to end, for example, the following commands are different:How do you use the entity command in Minecraft?
EntityData Command in Minecraft Java Edition (PC/Mac) entity is the entity you want to target. It can be either the UUID for an entity or you can use the @e target selector to target all entities or a type of entity.How do you target a single entity in Minecraft?
Bedrock Edition can use @r to target non-player entities via the type selector argument; in Java Edition, to select a random entity, use @e[sort=random] instead. In Bedrock Edition, @r can only target entities who are alive.Minecraft Execute Command [1.19] Tutorial
Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.
Images: Kampus Production, Pixabay, Pixabay, Kampus Production