I have a command block, among others, that checks an area and gives all players within that aren't holding a soul lantern in their offhand the Wither effect:
execute as @a[x=1237,y=57,z=-195,distance=..50,nbt=!{Inventory:[{Slot:-106b,Count:1b,id:"minecraft:soul_lantern"}]}] run effect give @s minecraft:wither 3 2 true
This command works on me totally fine, but others that enter the area are still withered despite holding the lantern. I've tried multiple variations of achieving this result, and all worked for me but seemed to fail to check if other players were holding the right item. Is there just a problem with how I'm defining what entities to target?
execute as @a[x=1237,y=57,z=-195,distance=..50] unless entity @s[nbt={Inventory:[{Slot:-106b,Count:1b,id:"minecraft:soul_lantern"}]}] run effect give @s minecraft:wither 3 2 true
It will execute all players in the area, and if the player holds a soul lantern offhand it will ignore it. Just like the original but I have separated the selectors. it might work better in multiplayer but I haven't tested it myself. That's why I just made a comment.