Sounds

Overview[edit]

Sounds are a key component to games. They are a great way to add atmosphere and immersion, whether through sound effects or music.

How to Use[edit]

Creating Sounds[edit]

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 Time Size Cost
Tier 1 0sec - 10sec 0MB - 0.75MB R$20
Tier 2 10sec - 30sec 0.75MB - 1.75MB R$35
Tier 3 30sec - 2min 1.75MB - 7MB R$70
Tier 4 2min - 7min 7MB - 20MB R$350
These rates are subject to change without warning.

Finding Sounds[edit]

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.

SoundUrl.png

Look Here for more resources regarding music.

Loading Sound in Place[edit]

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:

Add to Workspace[edit]

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 SoundIcon.png. Then, set the SoundId property:

SoundProperties.png

Add with Script[edit]

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:

local sound = Instance.new("Sound")
sound.SoundId = "http://www.roblox.com/asset/?id=27697743"
sound.Parent = game.Workspace.MusicBlock

Preload Function[edit]

If you have a large amount of sounds to load you can process them all at once with Preload.

Assets = {2253543,2434541,5133543,2423433,41143243,2453865,21433365,2154549}
 
for _, asset in ipairs(Assets) do
     Game:GetService("ContentProvider"):Preload("http://www.roblox.com/asset/?id=" .. asset)
end

Playing Sound[edit]

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).

sound:Play()

Note: Some users have noticed that some of their sounds play as soon as their game starts.

There used to be a bug where a sound would not play if the Play() function was called while the sound was loading (for instance if you called Play() right after setting the asset id). This bug has been fixed so sounds will always play if the Play() function is called.

In games where sounds are mysteriously playing as soon as the game starts it is likely that there are calls to Play() in some scripts that weren't noticed before this bug was fixed. If you hear unexpected sounds as soon as your game loads, it is recommended that you search through your scripts for any unintentional calls of Play() and remove them

Types of Sounds[edit]

Ambient[edit]

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 Sound[edit]

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:

  • Volume: The closer a player is to a 3D sound, the louder the sound will play for that player.
  • Stereo: If one side of a player is closer to the source of a 3D sound, the player's corresponding speaker will be louder.
  • Doppler Effect: If a 3D sound is approaching a player it will be heard at a higher pitch (and at a lower pitch if the sound is traveling away from the player).

API[edit]

For full API see Sound