Command blocks are confusing me

hey. is there a way to make an (for example) repetition command block by distance affect two players at the same time? I have two command blocks. one has something like execute @p[distance=..20] if scoreboard blackmusic matches 1700 run playsound blackmarket:music @s ~ ~ ~ 0.5 the other one is similar but it adds to the timer the problem is when i have two players in the same place it wont affect both another problem i have is making tp command blocks it affects the nearest player not the one who pressed it.
11 Replies
Admincraft Meta
Thanks for asking your question!
Make sure to provide as much helpful information as possible such as logs/what you tried and what your exact issue is
Make sure to mark solved when issue is solved!!!
/close !close !solved !answered
Requested by qwpm#0
F3DEX22
F3DEX222y ago
@p targets the nearest player by design I think you can't target the player that triggered the command block
Cooleg
Cooleg2y ago
@a just do @a
F3DEX22
F3DEX222y ago
That targets all players
Cooleg
Cooleg2y ago
yeah all players distance less than 20 for the first command for the second issue if you really cant handle it ever being inaccurate, then you could make it a /trigger command if it HAS to be with command blocks but most of the time solving that issue is more effort than its worth
F3DEX22
F3DEX222y ago
you're right
craz (NEW ACCOUNT)
is there a way to do them knowing exactly who pressed them? maybe with plugins or mods?
Cooleg
Cooleg2y ago
in theory yeah ig but why not just use a command at that point it would just be simpler overall
craz (NEW ACCOUNT)
cuz its having problems playing a sound with distance to more than two players and the command block that stops the sounds stops the sound to the player that is like 4 blocks behind me for example @Cooleg do you think i should be able to do it correctly with functions maybe? in a datapack
Cooleg
Cooleg2y ago
if the player runs the function themselves i think so im not a command block wizard i know its possible with /trigger commands
Deleted User
Deleted User2y ago
You can absolutely do it in a data pack more effectively. Tbh, anything you are doing for commands should be done in a data pack over command blocks. The sound playing over a distance is because you want to be using the "at" functionality of execute. You'd want to do something like execute as @a[distance=..20] at @s if score @s blackmusic matches 1700 run playsound blackmarket:music @s ~ ~ ~ 0.5 (I haven't tested this, or verified the syntax is correct)

Did you find this page helpful?