Sounds are a key component to games. They are a great way to add atmosphere and immersion, whether through sound effects or music.
Roblox supports uploading custom .mp3 files to play in your games and like Models, Decals, Plugins, etc, can be used by other developers in their games. To do this on the Roblox site, click on the Develop tab and select Audio on the left. You will then be prompted to upload a local file and give it a name.
Audio files must be in .mp3 or .ogg format and must be shorter than 7 minutes and smaller than 20 MB. The cost to upload a sound follows the following pricing structure (the price is determined by the highest tier a sound falls under):
|Tier 1||0sec - 10sec||0MB - 0.75MB||20|
|Tier 2||10sec - 30sec||0.75MB - 1.75MB||35|
|Tier 3||30sec - 2min||1.75MB - 7MB||70|
|Tier 4||2min - 7min||7MB - 20MB||350|
Sounds can be obtained on Roblox through the Catalog. After purchasing a sound, make note of the sound's id in the url. You will need this to load the sound in your game.
Look Here for more resources regarding music.
It is important to preload sounds so that they are ready to play whenever you need them. Whenever you set the asset Id of a sound it will begin preloading. There are several ways to do this:
To add a sound to the workspace directly, right click on the an object you want to be the parent in the Explorer and select Insert Basic Object > Sound . Then, set the SoundId property:
To add a sound with a script it first has to be created with Instance.new. Then, the sound id needs to be set, as well as the Parent object of the sound:
If you have a large amount of sounds to load you can process them all at once with Preload.
Playing a sound just requires the Play function. A sound will play immediately unless it has not finished loading. If the sound was loading when the Play call is made the sound will begin playing as soon as it has finished loading. Since loading can take a little bit of time, it is recommended to preload your sounds as soon as possible (ideally when the place first launches).
Ambient sounds are played at a constant volume throughout a place and are most commonly used to play music. A sound will be ambient if its parent is not a part.
3D Sounds are locational and are most commonly used for sound effects. A sound will be 3D if its parent is a part. 3D sounds have several behaviors:
For full API see Sound