How do I make it so when a player is holding a specific item in their hotbar or offhand, that a potion effect is given to them? [duplicate]

How do I make it so when a player is holding a specific item in their hotbar or offhand, that a potion effect is given to them? [duplicate] - Bokeh Photography of Person Holding Turned-on Iphone

I'm making a PVP-style server for a group of my friends and I, and I wanted to make it so when a player was holding a "Dark Gnome's Shadow Wand" (a stick) in their hotbar or offhand, that it would trigger a command block to give them the blindness potion effect. I got the command to work before with scoreboards, but it would target everyone, which made it difficult to balance around...is there a way to target only one player with custom named items such as this?



Best Answer

scoreboard players set @a potion 0  
scoreboard players set @a potion 1 {SelectedItem:{id:"XXX",tag:{XXX}}}  
effect @a[score_potion_min=1] ....  

That should do it. Just put 3 command blocks on clock after each other.




Pictures about "How do I make it so when a player is holding a specific item in their hotbar or offhand, that a potion effect is given to them? [duplicate]"

How do I make it so when a player is holding a specific item in their hotbar or offhand, that a potion effect is given to them? [duplicate] - Man in Brown Coat Holding White and Black Dslr Camera
How do I make it so when a player is holding a specific item in their hotbar or offhand, that a potion effect is given to them? [duplicate] - Woman in Pink and White Floral Sunglasses
How do I make it so when a player is holding a specific item in their hotbar or offhand, that a potion effect is given to them? [duplicate] - Woman Wearing White Shirt



How do you make it so when you hold an item you get an effect?

/take [player] [id] (amount) (metadata) Removes the given item from the player's inventory. If it succeeded, it outputs a signal to a comparator. If not, make sure not to remove a part of the items without outputting a signal.



Minecraft 1.18.2: How To Run a Command When a Player Holds a Certain Item




More answers regarding how do I make it so when a player is holding a specific item in their hotbar or offhand, that a potion effect is given to them? [duplicate]

Answer 2

**UPDATE**

You wanted it to target 1 person.
Simply make teams for each player, then copy the command block thingamiga by using the @a[team=XXX] where XXX is the team. Then, add everyone to their own team. This means it will only target 1 person / team at a time

To make teams:

/scoreboard teams add XXX 

To select the team:

/tp @a[team=XXX] OR /tp @p[team=XXX] (doesn't have to be tp) 

Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.

Images: Daria Shevtsova, cottonbro, Orhun Rüzgar ÖZ, Elīna Arāja