AudioLoader Module (Simple Resource)

Hi devs,

I made a simple AudioLoader module for my own game to manage audio better. Later, I decided to share it to everybody because why not?

So here’s the module!!: AudioLoader.rbxm (1.7 KB)

Usage

You can organize and manage all your sound IDs by customizing the AudioLoader.AudioList property. By default, this would be something like this:

audioMod.AudioList = { -- audioMod is the reference to the module's item inside itself.
	["Allies"] = {
		["Punch1"] = "rbxassetid://7468131335",
	}
} 

To load that one and only punch sound, we can write one of the following:

  • AudioLoader.LoadAudio("Punch1") OR
  • AudioLoader.LoadAudio("Allies.Punch1")

Both will return a Sound instance with the ID (in this case, rbxassetid://7468131335). The difference is that, the first identifier is more likely inaccurate especially when there are multiple IDs with the same name, so, the second one would be more specific.

Now, you might have noticed that there is one more method known as AudioLoader.LoadRandomAudio() (ignore the processStr() one, it’s for internal use only), it simply returns a ID from a given array of identifiers (name or path). Now, suppose that there the AudioList preoperty is something like this:

audioMod.AudioList = {
	["Allies"] = {
		["Punch1"] = "rbxassetid://7468131335",
        ["Punch2"] = "your ID here",
        ["Punch3"] = "your ID here"
	}
} 

If we want to pick one randomly from the three sounds, the LoadRandomAudio() could be used, it accepts a array of strings (identifiers) as its parameter, so we would write something like this:

AudioLoader.LoadRandomAudio({
    "Punch1", "Punch2", "Punch3"
})

And that’s all it is, happy coding!

Notes

Sound Instances returned by the two methods mentioned above are by default, parented to nil, in order for the sound to be successfully played to a client, please put it somewhere they can access. (such as ReplicatedFirst)

How would you rate this module?
  • Nice work! I might use it in my future projects.
  • Seems good. But I might not use this for now.
  • It doesn’t seem good. (Please give suggestions!)
0 voters
3 Likes