Local Sound Replication

So I’m planning to have it so as an event happens on the server, a local sound gets played on every client. The reason why I want the sound to be local is because every client has different settings for sound volume and I want them to adjust it accordingly.

How would I go about telling the client to play the sound? Would I create the sound on the server, fire a client event to all the clients so they can update the volume, then play it on the server?

What happens if a player joins the game after the sound has already been played? How would I go about updating the volume then?

Should I create a CollectionService just for these specific types of sounds??

2 Likes

Personally, I don’t “replicate sound playback”. I set up SoundGroups in SoundService and assign sounds to a respective SoundGroup. A client’s settings values determine the volume of the SoundGroup object, while the server (or client) play the raw sound objects.

In this way, the client will have the SoundGroup Volume property to manipulate the volume of sounds (I set all sound volumes to 1, as SoundGroup.Volume is a multiplier) while sound playback is handled regularly as expected. Automatically accounts for new joiners and players already in the game.

8 Likes

What happens if the sound has to be coming from a part tho?

1 Like

Doesn’t change, do the same thing. SoundGroups work across sounds both in and out of the 3D View. If the sound needs to come from a part, handle the Sound like you normally do - play it from the client, play it from the server or use a remote to facilitate playback (though typically if you need a sound to replicate, using a remote is not the greatest idea - server playback already replicates).

The point is that the SoundGroups are there to help manage the volume of sounds only. How you play sounds should not change, so long as your implementation already covers for client sounds and/or replication in a RespectFilteringEnabled environment (or not, as well).

If your SoundGroups already exist at runtime, then all that’s expected of you is to modify the Volume property when the client joins and/or changes their own properties. Playback remains unaffected, it’s just the volume of sounds from thereon that’s managed client-side. Remember that the volume of a SoundGroup is a multiplier though, not an enforcer.

CollectionService has the potential to be a good alternative if you’re looking strictly for an raw value over a multiplier but I wouldn’t recommend it given how much maintenance that would require (having to constantly manage many sounds and such).

1 Like

I dont understand. Like if you have multiple sounds all coming from different locations on the map, how will you apply soundgroup to this?

Put the SoundGroup object in SoundService and assign the SoundGroup property of the sounds on the map to that SoundGroup. The SoundGroup object just needs to be in the SoundService; keep your sounds as-is, except for the SoundGroup property - change that to a SoundGroup.

e.g.

  • SoundGroup “Gunshots” in SoundService
  • SoundGroup “AmbientEffects” in SoundService
  • Any gunshot sound objects have the SoundGroup property set to the Gunshots SoundGroup
  • Same as above, except ambient sound objects for AmbientEffects
1 Like

Omg i’ve been doing the caveman style way the whole damn time.

For clarity’s sake; what is the caveman style?

I knew about sound groups, but I didn’t realize that sounds had a SoundGroup property.

What I was doing was basically just have the clients iterate through a specific folder called “EffecSounds” and set the volume that way.

1 Like

Oh, I see. Yeah I was somewhat under that impression too - when SoundGroups were first introduced, I thought that you had to put actual Sounds into the SoundGroup or just ignore them at all and instead iterate through a Folder and change volume. Turns out you can just set the SoundGroup property of Sound objects and keep SoundGroups separate in SoundService.

The one thing I’m very cautious about (which I’ve said three times now, lool) is that SoundGroup volume is only a multiplier. I don’t think that it’d matter too much - imagine a background audio with 25% regular audio (0.25) and the player sets their ambience sounds to 50%. Multiply magic.

Where should the SoundGroups be grouped under?

You can leave them in the SoundService, either as direct children or in Folders. I personally recommend SoundService because it makes sense to store SoundGroups there and its contents replicate. On the client, you would fetch them like you’d normally fetch a storage descendant. Example:

local SoundService = game:GetService("SoundService")
local GunshotsSoundGroup = SoundService:WaitForChild("Gunshots")
2 Likes