How can I make a command block kick specific player on their death?

How can I make a command block kick specific player on their death? - Anonymous soccer player on field during match

I am trying to make command blocks kick me when I die on a multiplayer server I own, running 1.17.1, I have been trying to figure this out for an hour now and still have not gotten this to work.

before posting this question I have tried adding myself to a team then checking if that team has died using execute at @a[team=ryan,scores={deaths=1..}] in a repeat command block.

I then had that command block run into a chain command block containing the command scoreboard players reset @a[team=ryan,scores={deaths=0..}] deaths using this to reset the deathCount score back to 0.

This command then ran into a impulse command block containing kick (playername)

I will put some images of the command blocks in case I have a typo and to give a better understanding of what I am doing.

Command blocks on ground : enter image description here

1st repeating command block : enter image description here

2nd chain command block : enter image description here

3rd impulse command block : enter image description here



Best Answer

First, you need to make sure you have added the score you test for.

This will be the command to add the score of name deaths that tests for how many times a player has died:

/scoreboard objectives add deaths deathCount

Then, you need to replace the at in the first command with if entity:

execute if entity @a[scores={deaths=1..}]

Then it needs to go into a chain command block that is set to Conditional:

Chain command block

The next command will be:

execute as @a[scores={deaths=1..}] run kick @s

Here you need to make sure that you use as so you can use @s later in the command.

The last command block needs to be the same as the 2nd and have this command:

scoreboard players set @a[scores={deaths=1..}] deaths 0


Note

This will kick any player that dies if you would like to only kick yourself you can just replace the @a[scores={deaths=1..}] part with "Your Name"

And if you do use teams, you can keep the team part in the selector and this will kick anyone on that team if they die, just make sure you have specified the same targets in all the command blocks.


This works but I would rather do it like this:

First command:

execute if entity @a[scores={deaths=1..}] run kick @a[scores={deaths=1..}]

Note that you need to specify which player you want to target both in the execute part and in the run part.

Next, it will go into a chain command block with Conditional as before with the command:

scoreboard players set @a[scores={deaths=1..}] deaths 0

Now you only have two command blocks, instead of three:

Command blocks




Pictures about "How can I make a command block kick specific player on their death?"

How can I make a command block kick specific player on their death? - Side view of jumping little girl in jeans and jumper kicking colorful ball playing on sports yard
How can I make a command block kick specific player on their death? - Soccer Player Kicking White Gray Soccer Ball on Green Grass Field
How can I make a command block kick specific player on their death? - Man in Black Pants Playing Soccer during Daytime



How do you make a command block kick someone?

The only way I know how to forcibly kick a player from Minecraft via command blocks is to teleport them to the edge of the world then do a relative teleport over the edge. However, there is no coming back from this without modifying the player's positions in the . dats. This would only be useful as a banning method.

How do you execute a command when someone dies in Minecraft?

Here's the command to add the scoreboard: /scoreboard objectives add deaths deathCount , then, in a separate command block, put: /scoreboard players set @a deaths 0 .

Can you DEOP someone with a command block?

You cannot. There are various commands that are unavailable, probably due to the ability for abuse (such as reopping yourself after having your admin privileges revoked).



How to kill someone with a command block!




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

Images: RF._.studio, Allan Mas, Pixabay, Pixabay