We use cookies on this site to enhance your user experience

Sep 14 2018, 11:36 AM PST 5 min

 

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

Creating Sounds

Roblox supports uploading custom audio files to play in your games. Just like models, decals, plugins, etc., audio files can also be used by other developers in their games.

To do this on the Roblox site, click on the Create 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 0 seconds - 10 seconds 0 MB - 0.75 MB R$ 20
Tier 2 10 seconds - 30 seconds 0.75 MB - 1.75 MB R$ 35
Tier 3 30 seconds - 2 minutes 1.75 MB - 7 MB R$ 70
Tier 4 2 minutes - 7 minutes 7 MB - 20 MB R$ 350

Finding Sounds

Sounds can be obtained on Roblox through the Audio section of the Studio Toolbox.

RobloxToolboxSounds.jpg

After adding a sound, it will appear in your Explorer. Make note of the sound’s ID in the URL. You will need this to load the sound in your game.

robloxSoundProperties.jpg

Loading Sound in a Place

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

To add a sound to the workspace directly, right-click on an object you want to be the parent in the Explorer and select Insert ObjectSound. Then set the Sound/SoundId|SoundId property:

SoundProperties.png

Add With Script

To add a sound with a script, it first has to be created with Instance|Instance.new(). Then theSound/SoundId|SoundId needs to be set, as well as the Instance/Parent|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

If you have a large amount of sounds to load you can process them all at once with ContentProvider/Preload|Preload().

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

Playing Sound

Playing a sound just requires the Sound/Play|Sound:Play() function. A sound will play immediately unless it has not finished loading. If the sound was loading when the Sound/Play|Sound: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).

Types of Sounds

Ambient

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

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

Tags:
  • sound
  • audio