How to give levitation to a player when the player is holding an item in his offhand

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.


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