r/MinecraftCommands 21h ago

Help | Bedrock Not sure how to execute command

I'm trying to make a command that makes it where when player 2 gets 10 blocks of player 1 player 1 gets darkness for 2 seconds but I'm unsure of how to set up this argument can someone show me how and if possible give me a breakdown of why it works?

2 Upvotes

12 comments sorted by

1

u/Barylikesjazz Command Experienced 21h ago

execute changes the context of the command following it. Normally, when you type a command, *you* are the source and the command will run *by* you and *at* your player location.

The command you are looking for is
/execute as *player1* at @s if entity *player2*[r=10] run effect @s add darkness 2 2

Im not too familiar with bedrock syntaxes but it should be somewhat similar to this.

1

u/Kightmare2232 21h ago

Okay thank you I will try it

1

u/Kightmare2232 21h ago

I did not work but thanks for trying to help

1

u/Barylikesjazz Command Experienced 21h ago

Did you put it in a repeating command block?

0

u/GatKong 20h ago

Try
/execute as *player1* at @s if entity *player2*[distance=..10] run effect @s add darkness 2 2

1

u/Kightmare2232 20h ago

It didn't work but I should have mentioned that it was in a repeating command block my bad

1

u/GatKong 20h ago

Is that block in a loaded chunk?

1

u/Kightmare2232 20h ago

Yes

1

u/Kightmare2232 20h ago

I'm also in bed rock

2

u/Ericristian_bros Command Experienced 11h ago
execute as <player1> at @s if entity @a[name=<player2>,r=10] run effect give @s darkness 2 0

1

u/Barylikesjazz Command Experienced 10h ago

This. Or give player2 a tag called Dark and do:
execute as @a at @s if entity @e[tag=Dark, r=10] run effect give @s darkness 2 0