Sounds and Music
Sounds and Music
While building a game, it’s easy to overlook the importance of sounds and music. Combined creatively, these can set an atmospheric or exciting tone, build suspense, and bring life to your game’s characters.
A wide array of audio can be searched for in the Toolbox by clicking the Marketplace tab and selecting Audio from the menu.
Within the view, you can search by name or click the button to:
- Search by Creator (the Roblox user who published the file).
- Search by Sound Length to more easily distinguish short sound effects from longer music tracks.
- Sort audio by relevance, most frequently taken, number of “favorite” votes, most recently updated, or highest rated.
Audio can be previewed directly within Studio by clicking the play button in the corner of each listing. Once you locate an audio file to use, right-click the listing and select Copy Asset ID (this ID will be required for playback testing in the sections below).
Uploading Custom Audio
On Roblox, uploading audio files comes at a small cost in Robux — this accounts for the time it takes moderators to review every sound file that users upload.
To upload audio on the Roblox site:
- Visit the Create Audio page where you’ll be prompted to upload a local file and give it a name. Audio files must be .mp3 or .ogg format, shorter than 7 minutes, and smaller than 19.5 MB.
- Click the Estimate Price button. The cost to upload an audio file is based on the following pricing structure:
|30 seconds – 2 minutes||70|
- Click the Purchase button to upload the audio file.
- Once the file is uploaded, it will appear in the list on the page. Click the name to open its dedicated page and copy/record its numeric ID from the URL in the browser window (this ID will be required for playback testing in the sections below).
Playing background music in a game can be accomplished via scripting, as follows:
- In the Explorer window of Studio, add a new
- Rename the new script AudioPlayer.
- In the script, delete all existing lines and paste in the following code:
preloadAudio()function (lines 7-22) and
- Create a new
LocalScriptinside StarterPlayerScripts (a child of StarterPlayer).
- Playtest the game and you should hear the track name specified on line 14 playing in the background.
Unlike background music, sounds will often originate from a specific place or object inside the game — the engine of a vehicle, the battle cry of an enemy, etc. However, they may also be played as an “ambient” sound like wind blowing or rain falling.
A sound placed in a
BasePart or an
Attachment will emit its sound from the part’s
BasePart/Position|Position or the attachment’s
Attachment/WorldPosition|WorldPosition. These are considered 3D sounds and they share the following traits:
- Volume — A 3D sound will play louder as a player gets closer to its source.
- Stereo — If one side of a player is closer to the sound’s source, the player’s corresponding speaker will be louder.
- Doppler Effect — If the source of a 3D sound is approaching a player, it will play at a higher pitch. Similarly, it will play at a lower pitch if the source is traveling away from the player.
If the source part/attachment already exists in a place, you can add a 3D sound directly within Studio:
- In the Explorer window, insert a new
Soundobject as a child of the source object.
- Select the new sound object and, in the Properties window, locate its SoundId property. Enter rbxassetid:// followed by a valid audio ID, for instance rbxassetid://1847352423.
- Toggle its Playing property on (sounds do not play automatically, so you must explicitly tell them to start playing).
- Playtest the game and observe the 3D sound’s qualities based on your character’s proximity to the source.
Ambient environmental sounds like wind and thunder don’t need to be attached to a part because they come from all around the player. As such, these type of sounds can be played using the same scripts shown in Playing Music above.
Sound effects for interactive GUI objects can be played using the same
ModuleScript shown in Playing Music above. Instead of playing a sound immediately, however, you can hook it up to the
GuiButton/Activated|Activated event listener for the button.
In StarterGui, add a new ScreenGui, then create a new TextButton within it. If you’re unfamiliar with buttons and their basic options, see
articles/Creating GUI Buttons|Creating GUI Buttons.
Select the new button and insert a
- In the script, delete all existing lines and paste in the following code. If desired, input a different sound name and audio ID on line 9.
- Playtest the game and you should hear the sound name specified on line 17 play when the button is activated.