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.

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

1 Answer 1

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
3
  • 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. Commented Mar 27, 2020 at 15:39
  • I tried with @s but didn't work. Does this command work on te version 1.15.2
    – LPA 3227
    Commented Mar 27, 2020 at 18:41
  • Yes, it does. Are you sure that you're holding an item named "CLOUD" in your offhand? Commented Mar 27, 2020 at 20:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .