0

I'm making a server and I need to make a command that gives levitation to a player when he is holding a specific item in his offhand.

I already have this working for the mainhand:

/execute as @a[nbt={SelectedItem:{tag:{display:{Name:"{\"text\":\"CLOUD\"}"}}}}] run effect give LPA3227 minecraft:levitation 1 5 true

But I need it for the offhand.

  • 1
    You're always giving the effect to yourself, not whoever is holding the item. Use @s in the effect command instead. – AMJ Mar 26 at 3:24
  • i now but i'm trying to do for me first – LPA 3227 Mar 26 at 3:46
1

The off-hand (which is the proper term, because left and right hand can also be switched in the skin settings) is a slot with the Slot ID of -106. So this command checks if there is a slot that has the ID -106 and your desired item in it:

/execute as @a[nbt={Inventory:[{Slot:-106b,tag:{display:{Name:"{\"text\":\"CLOUD\"}"}}}}] run effect give LPA3227 minecraft:levitation 1 5 true
|improve this answer|||||
  • Thank you. But is not working – LPA 3227 Mar 26 at 18:33
  • It does for me. What error message do you get? Are you sure that you're holding an item with the name "CLOUD" in your off-hand? And that you're playing as the account "LPA3227"? You could also try simply replacing the name with @s, that's probably what you want anyway. – Fabian Röling Mar 27 at 15:39
  • I tried with @s but didn't work. Does this command work on te version 1.15.2 – LPA 3227 Mar 27 at 18:41
  • Yes, it does. Are you sure that you're holding an item named "CLOUD" in your offhand? – Fabian Röling Mar 27 at 20:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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