Command Block Question for "if, then" statement
Emma Newman
Published Jul 17, 2026
On the latest version of Minecraft Bedrock edition is it possible to have a command block (When activated) check for the nearest player's name and kill them if it does not add up to a pre-entered name?
For example, if "Player1" steps on the pressure plate that activates the command block they do not die, however, if "Player2" steps on the pressure plate that activates it, they die.
Edit: Using more than one command block.
2 Answers
Simpler solution
There is often a better command that can be used instead of /testfor, if you have a pressure plate that should only kill "Player2", you can simply use this command:
/kill @a[name=Player2,x=~,y=~2,z=~,r=1]This is assuming that you have the command block 2 blocks under the pressure plate.
More general solution with /execute
Whenever you want to use /testfor, you can likely use /execute instead, simply by putting the target selector from the /testfor command into it.
If you want to kill "Player2" if a zombie is within 5 blocks distance from the command block, then you could use /testfor @e[type=zombie,r=5] in a command block and then /kill Player2 in a conditional chained command block.
This could be done more easily by putting the target selector from the first command into an /execute command:
/execute @e[type=zombie,r=5] ~ ~ ~ kill Player2Even more general solution
In some extremely rare cases I can't think of any situation where you really need anything beyond /execute right now even this may not be enough, maybe you want to execute several commands as a specific group of mobs that may not be detectable with the same target selector after every command.
If you really need something like this, then you can set up a scoreboard objective:
/scoreboard objectives add objectives dummyYou would use one repeating command block that continuously sets the score of all entities to 0, the scoreboard objectives will be used to determine what entities to execute as:
scoreboard players reset * objectivesFor every system that you want to set up you would then set the scoreboard score with the same target selector you would use with /testfor, or /execute. Each score value should be unique to every setup:
scoreboard players set @e[type=zombie] objectives 1You would then use a chain of command blocks, one for each command that you want to execute. You would likely use /execute again, maybe in a command like this:
execute @e[scores={objectives=1}] ~ ~ ~ kill @a[r=5]This example would kill all players within 5 blocks of any zombie, it could be done more easily with /execute @e[type=zombie] ~ ~ ~ kill @a[r=5].
You can use testfor to test if the player is at the specified position, then use a comparator to trigger another command.
Put testfor @p[name=Name,x=X,y=Y,z=Z,r=maxRadius] in an impulse, unconditional, needs redstone command block that would activate when the pressure plate is activated. Name is the name of the player (in your example Player2). maxRadius is the maximum distance (Euclidean) from X, Y, Z that the player needs. Alternatively, you can use dx, dy, and dz to define cubic volumes. Without these, testfor will always be successful as it would find Name, no matter how far away.
For example: testfor @p[name=Player2,x=10,y=40,z=5,r=2] would activate the second command if Player2 is within 2 blocks of 10, 40, 5.
Then put a comparator (comparison mode) facing away from the command block into another command with the command, such as kill Player2.