TransWikia.com

Why is my /playsound command not playing even though I am in range of the target selector?

Arqade Asked on June 16, 2021

I’m in the process of building a multiplayer adventure map and wanted to play ambient music when players enter and as long as they remain in certain areas.
However one target selector gave me a lot of trouble over the past two days and I can’t figure out what’s wrong.

I made a custom soundpack and tested everything in a singleplayer world on a bit of a smaller scaling, which worked quite nicely.
For knowing how long the sound should play I’m using the scoreboard dummy variable musicRemaining, which is automatically set to 0 if a player joins the world, so they are targetable by the repeating command block playing the sound.
Players whose musicRemaining-score equals 0 and are also standing inside the rectangular prism specified in the repeating command block get to hear a nice little ambient music.
The signal then travels to a chained command block, setting the value of musicRemaining to whatever the length of the track in ticks may be (2640 in this case).
As soon as a player in the area has a musicRemaining count of >= 1, the last second repeating command block starts decreasing this value by 1 per tick. The loop runs perfectly for as long as the player remains. If a player exits the area, a repeating command block stops the music and a chained command block sets the scoreboard value to 0 so the next track can instantly start.

So far, so good, but now comes the problem I encountered in the larger scale version of the construct.
I will try to be as specific as I can be and provide all important information to solve this issue.

The first command block(repeating,always active) plays the sound to a player if the conditions are met. It holds the following command:

/playsound minecraft:ambient.custom.worldspawn music @a[dx=23,dy=10,dz=19,scores={musicRemaining=0}]

The second command block(chain, always active) is connected to the first one and executes right after it:

/scoreboard players set @a[dx=23,dy=10,dz=20,scores={musicRemaining=0}] musicRemaining 2640

The third command block(repeating, always active) runs on its own:

/scoreboard players remove @a[dx=24,dy=10,dz=19,scores={musicRemaining=1..}] musicRemaining 1

Both, the second and the third command block execute their task flawlessly in the selected area, however there seems to be a problem with the target selector in the first block, since it does not always activate when the musicRemaining-condition is met and one stands in the area, unless the player is in a radius of 14 blocks, similar as if the arguments were distance=..14.
Strange enough it still cuts the selection area as expected in any other direction.
So I’m trying to select everything in a cuboid, only get everything inside of a way smaller sphere, but still bound to the restrictions I set in place.

front-view

The colored blocks represent the area a signal is received, with the smooth blocks activating as soon as the player hitbox enters, the others only if the players cross 0.5 of the block width.

inside-view

(behind)command block view

If I set the first command block to say something like "hi" and let the others go on about their business
it will fire once musicRemaining reaches 0 as it should do.
With the music command it only works in the purple area (tested by manually resetting the scoreboard variable to 0).

Any tips or advise would be really appreciated, I hope it is something trivial which I just overlooked all the time..

One Answer

You are not using the target selector incorrectly. It's because the sound from /playsound is being played cannot be heard from locations outside the 14-block dome you have found.

Using a target selector allows the selected players to hear the sound only if they're within range. The range is 16 blocks, but because your command blocks are slightly farther out, the range is actually 14 blocks inside your area.

To get the sound to play even if your players are not within 16 blocks of the command block, you'll need to use the minVolume argument. From the Minecraft Wiki:

Specifies the volume for targets outside the sound's normal audible sphere. If a target is outside the normal sphere, the sound is instead centered some short distance from the target (less than four blocks away), and minimumVolume determines its volume. Must be from 0 to 1.

Fixed command:

playsound minecraft:ambient.custom.worldspawn music @a[dx=23,dy=10,dz=19,scores={musicRemaining=0}] ~ ~ ~ 1.0 1.0 1.0

Correct answer by ExpertCoder14 on June 16, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP