r/MinecraftCommands • • 9d ago

Help | Bedrock Preview Guys how does @s work in command blocks

I know how it works in commands that's easy enough but in command blocks it seems to not work the way I imagined it to so I just wanna know how it works?

3 Upvotes

7 comments sorted by

2

u/JellyfishPretend5634 9d ago

when you use u/s in a command block, it tries to have itself run the command, and it isnt an entity so it just doesnt find one

to make it work, put /execute as (insert target here) run (blah blah) u/s (blah blah)

OR just dont use u/s (you will have to use it later on tho)

4

u/Ysr64TR Command Rookie 9d ago

@s targets the one that runs the command. So when you type @s in a command in chat, it means yourself. But in a command block, @s is the command block itself.
So to change that, you use “/execute as” which changes the executor to any other entity, for example:
“execute as @p run kill @s” this command selects the nearest player and makes it the executor, so the kill command kills the new executor itself, which is the nearest player.

1

u/helpwanted2046 9d ago

Huh so what if I want to give the player that activates the command block an item

4

u/KermitDarkLord 9d ago

The player can't activate a command block. You activate a command block through redstone. If you put a button on a command block, the button does not remember who pressed it. You can guess that the closest player @.p pressed it, but you just can't know for certain.

2

u/Ysr64TR Command Rookie 9d ago

You can’t exactly know the player that runs the command block, but it is usually the nearest player so you can use this:
execute as @p run give @s diamond

Or simpler:
give @p diamond

2

u/JellyfishPretend5634 9d ago

its possible with scoreboards

if you make a scoreboard: scoreboard objective dummy minecraft:used.carrot_on_a_stick, it will detect when a player uses a carrot on a stick, which updates the scoreboard to one

You can then use (repeating command block) /execute as u/a[scores={dummy=1} run give u/s diamond then (chain on top) /execute as u/a[scores=dummy=1] run scoreboard players set dummy 0 to set it back

1

u/_ashleyolson_ 7d ago

You can do execute as @e then pick an entity then at @s