[Open Source] Audio Manager

What is it?

This modulescript is intended to help you with managing all the sounds (besides the one you would need in ReplicatedFirst) your game will need. It provides a good amount of functionality and control over your sound instances. You can find the ROBLOX Model here and the Github Repository here.

The system recognizes two types of sounds: background music and sound effect. Background Musics are audios that can have only one instance of them being played at any given them, you can’t play two background musics at the same time. Sound Effects are audios that can overlap and play simultaneously (think about an explosion sound effect).

With that in mind, I will now talk about the structure of the system.

AM

As you can see, there are two folders for holding the two different types of sounds and there is a folder to use Sound Groups if need be. Inside the two folders, however, you can put multiple folders and sounds.

AM BM

In this example, I created a new folder called Battle Music with three sounds in it. I also have a string value object inside each of the sound called “Id”. This is another feature of the system where it optionally allows you to refer to the sound by this Id instead of sacrificing its descriptive name (in the sense that while “Persona 2 - Eternal Punishment: Battle” is very descriptive but you would rather refer to it as “Batte Music 1” in your scripts).

AM SE

In this example, I created a “Slash” folder with multiple different slash sound effects. Remember you are not limited to just one folder, the system is recursive and so you inside the “Slash” folder, you could create folders for slash sounds of different weapons. Another feature of the system is assigning weight to sounds using an optional number value called “Weight” (sounds without this number value default to a weight of 1). The weight will allow you to prioritize one sound when you let the system choose a sound at random from a group of sounds.


How to use it?

The system exposes five useful functions:

  • PlaySoundEffect(path)

  • PlaySoundEffectAtPosition(path, position)

  • PlaySoundEffectOnInstance(path, instance)

  • PlayBackgroundMusic(path)

  • StopBackgroundMusic()

Their usage is best demonstrated with a practical example.

From Line 11 to 13, we are specifying the path to “Slash 1” sound instance that is inside “Slash” folder. We play that sound effect in three different ways using the three different functions.

From line 15 to 18, we specify the “Slash” folder instead of a sound instance. This allows the system to choose a weighted random sound out of the group.

In the last few lines, we are playing different background musics. The transition between them is smooth so don’t worry.

Remember when creating a path, the names (or the one specified with the id string value feature) are case sensitive and should not contain “/”.

19 Likes

Hey this is cool man, I’ll check it out.

Is this client-side (ie. every player will hear their own music out of sync), or is it server-sided (every player will hear the same sounds). I’ve had troubles developing audio for my games in the past and I’m wondering if this project might have my solution.