Sound Objects

A Sound object is an object that emits audio within your experience. Studio assigns each audio asset a unique asset ID that you can assign to Sound objects to play a specific sound effect or music sample. You can either set this audio to play automatically at runtime, or trigger it to play from your scripts.

You can use the Creator Marketplace to find a variety of free-to-use audio assets for Sound objects to play, or you can import custom audio that you are certain you have permission to use, such as audio you make yourself. Aside from customizing individual Sound objects, you can also group Sound objects together under a sound group to control the volume and dynamic effects properties of multiple audio sources at once.

Creating Sound Objects

There are three locations you can create a Sound object, and each location determines how audio emits and volume changes in relation to the user's position within the experience:

Location How Audio Emits How Volume Changes
Child of a block, sphere, or cylinder BasePart. Audio emits outward from the entire surface of the part. Volume changes depending on the distance between the user's sound listener and the position of the part, as well as part's size.
Child of an Attachment, MeshPart, TrussPart, WedgePart, or CornerWedgePart. Audio emits outward from the single attachment point. Volume changes depending on the distance between the user's sound listener and the position of the attachment.
Within the Workspace without a parent object. Audio emits throughout the experience. Volume and pan position remain the same regardless of the user's position or rotation.

It's important to determine where you want to create a Sound object because its location affects how users hear its audio. If you want users to only hear audio near a specific position, you must parent the Sound object to a BasePart or Attachment for them to hear positional audio. However, if you want users to hear audio regardless of their position, you must insert a Sound object directly into the Workspace without parenting it to another object for them to hear background audio, preferably under the SoundService container for organization purposes.

Positional Audio

Positional audio is audio that users can only hear near a specific position within the experience. There are two types of positional audio you can utilize: volumetric and point source.

Volumetric

Volumetric audio is the most realistic audio option, as it dynamically changes depending on the user's position to the audio source. For example, if the user is within a BasePart with a child Sound object, audio plays all around the user, similar to music in headphones playing at the same volume in each speaker. When the user exits the part, audio gradually decreases in volume and becomes more directional per speaker, moving around the user's head when their listener rotates. For information on the properties that control how loud your audio is at different distances from the part, see RollOffMinDistance and RollOffMaxDistance.

The size of the BasePart also affects the audio's volume, as larger BaseParts produce a wider area in which users can hear the audio and when a user navigates away from a large BasePart, volume decreases slower. The following example displays a BasePart that is the size of a city with a Sound object playing ambient audio. Users A and B experience the audio differently: user B is closer to the large BasePart, and they mostly hear the audio around the same loudness in both speakers. Conversely, user A is further away from the city, so the audio they hear is quieter and more directional than user B, playing at differing loudness in each of their speakers.

Volumetric audio is useful for any audio that needs to be immersive around a user and change dynamically depending on the user's position, such as a concert stage or ambience zones like rainfall. When you experiment with placing a Sound object on BaseParts of different sizes and positions from users, you can hear how immersive volumetric audio can be.

To create a Sound object for volumetric audio:

  1. In the Explorer window, select SoundService.

  2. In the Properties window, navigate to the VolumetricAudio property, then set it to Enabled.

  3. In the Explorer window, hover over a BasePart, then click the ⊕ button. A contextual menu displays.

  4. From the menu, insert a Sound.

  5. In the Properties window, navigate to the SoundId property and input a valid audio asset ID.

  6. (Optional) If you want the audio to start playing when the experience begins, enable the Playing property.

Point Source

Contrary to volumetric audio, point source audio only emits from a single point source. This type of audio is useful for explosions, impact noises, electronic devices, and dialogue.

To create a Sound object for point source audio:

  1. In the Explorer window, hover over an attachment, truss, wedge, or corner wedge, then click the ⊕ button. A contextual menu displays.

  2. From the menu, insert a Sound.

  3. In the Properties window, navigate to the SoundId property and input a valid audio asset ID.

  4. (Optional) If you want the audio to start playing when the experience begins, enable the Playing property.

Background Audio

Background audio plays at the same volume no matter where the user travels within your experience. This type of audio is useful for music that you want to play for users, especially when you want to create a soundtrack of multiple audio files.

It's best to keep all Sound objects for background audio in a single location of the Workspace for organization purposes as you continue to add and edit audio within your experience. The following example stores the new Sound object under the SoundService container, as this service determines how Sound objects play in experiences.

To create a Sound object for background audio:

  1. In the Explorer window, hover over SoundService, then click the ⊕ button. A contextual menu displays.

  2. From the menu, insert a Sound.

  3. In the Properties window, navigate to the SoundId property and input a valid audio asset ID.

  4. (Optional) If you want the audio to start playing when the experience begins, enable the Playing property.

  5. (Optional) If this Sound object is the only track you want to play in the place, enable its Looped property.

Customizing Sound Objects

Sound object properties work together to influence how users experience your audio, such as:

Volume

The Volume property allows you to set the volume of your audio anywhere from 0 (silence) to 10 (booming). If you want to change the volume of multiple Sound objects at once, parent them under a sound group.

RollOffMinDistance and RollOffMaxDistance

RollOffMinDistance and RollOffMaxDistance determine the range of how a user perceives volume from positional audio. For volumetric audio, RollOffMinDistance is the minimum distance in studs that audio begins to decrease in volume when the client's listener moves away from the parent BasePart, and RollOffMaxDistance property is the maximum distance in studs that a client's listener can hear audio from the surface of the object.

For point source audio, RollOffMinDistance and RollOffMaxDistance work similarly to volumetric audio, but the roll off distance these properties control doesn't surround the object, it only influences the distance outward from the point source.

RollOffMode

The RollOffMode property allows you to decide how audio fades as the distance between the user's listener and the Sound object's parent increases. You can set this property to one of four values of the RollOffMode enum.

RollOffMode Description
Inverse (default) Volume initially fades abruptly from RollOffMinDistance, but volume fading becomes more gradual the closer a user is to reaching the RollOffMaxDistance. Once they reach the RollOffMaxDistance, the audio falls silent.
Linear Volume fades linearly between RollOffMinDistance and RollOffMaxDistance. Once a user reaches the RollOffMaxDistance, the audio falls silent.
InverseTapered Volume follows the inverse model when close to RollOffMinDistance and the linear square model when a user is close to RollOffMaxDistance. Audio approaches silence at the maximum distance point.
LinearSquare Volume fades between RollOffMinDistance and RollOffMaxDistance with a linear squared relationship. Audio approaches silence at the maximum distance point.

PlaybackSpeed

The PlaybackSpeed property allows you to determine the speed your audio plays. For example, if you set the PlaybackSpeed to a value of 2, your audio plays twice as fast and one octave higher in pitch. Similarly, if you set it to a value of 0.5, your audio plays twice as slow and one octave lower in pitch.

TimePosition

The TimePosition property displays, in seconds, what position within the audio sample a user is currently hearing. This property is useful for either only playing a section of the audio sample, or triggering an event to occur once audio reaches a specific position. For example, the following code sample causes a particle emitter to emit a white ring particle above a part within a limited time range of an audio track.


1local RunService = game:GetService("RunService")
2
3-- Create a new part
4local part = Instance.new("Part")
5part.Anchored = true
6part.Color = Color3.new(0.75, 0.2, 0.5)
7part.Size = Vector3.new(2, 1, 2)
8part.Material = Enum.Material.Neon
9part.Position = Vector3.new(0, 4, 0)
10part.Parent = workspace
11
12-- Create an attachment on the part
13local attachment = Instance.new("Attachment")
14attachment.Position = Vector3.new(0, 0.5, 0)
15attachment.Parent = part
16
17-- Create a particle emitter on the attachment
18local emitter = Instance.new("ParticleEmitter")
19emitter.Rate = 5
20emitter.Lifetime = NumberRange.new(1.5, 1.5)
21emitter.Texture = "rbxassetid://1266170131"
22emitter.Speed = NumberRange.new(1, 1)
23emitter.Size = NumberSequence.new{NumberSequenceKeypoint.new(0, 1), NumberSequenceKeypoint.new(1, 6)}
24emitter.Transparency = NumberSequence.new{NumberSequenceKeypoint.new(0, 1), NumberSequenceKeypoint.new(0.25, 0), NumberSequenceKeypoint.new(1, 1)}
25emitter.Orientation = Enum.ParticleOrientation.VelocityPerpendicular
26emitter.Parent = attachment
27
28-- Create a sound on the attachment
29local sound = Instance.new("Sound")
30sound.SoundId = "rbxassetid://1835405646"
31sound.Parent = attachment
32
33-- Play the sound
34sound:Play()
35
36-- Start checking if emitter should be enabled
37RunService.Heartbeat:Connect(function()
38 -- Enable the emitter within a time range of the audio; otherwise disable it
39 if sound.TimePosition >= 5 and sound.TimePosition < 20 then
40 emitter.Enabled = true
41 else
42 emitter.Enabled = false
43 end
44end)
45

Looped

The Looped property allows you to repeat audio after it has finished playing. When set to true, the Sound object's audio plays again. This is useful to apply to background audio to ensure your experience never has abrupt silence.

Scripting Sound Objects

Playing Audio Contextually

Aside from auto-playing audio through the Sound object's Play() method, you can play audio contextually from a LocalScript by calling Play() on the corresponding Sound object. For example:


1local sound = Instance.new("Sound")
2sound.SoundId = "rbxassetid://9120386436"
3sound.Looped = true
4sound.Parent = workspace
5sound:Play()
6

Alternatively, if the place will feature multiple tracks, you can play a specific track from a LocalScript:


1local SoundService = game:GetService("SoundService")
2local musicTrack = SoundService:FindFirstChild("LucidDream")
3if musicTrack then
4 musicTrack:Play()
5end
6

Playing Interface Audio

You can play interface audio for GuiObjects, such as buttons and labels, by hooking up a Sound object to the Activated event listener of the GuiObject. This lets you provide auditory feedback to users, such as when they hover over a GuiObject or select it.

To play a Sound object's audio when a user activates a GuiObject:

  1. In the Explorer window, hover over a GuiObject, then click the ⊕ button. A contextual menu displays.
  2. From the menu, insert a LocalScript.
  3. Paste the following code into the script, then replace SOUND_NAME with the name of your sound object.

1local SoundService = game:GetService("SoundService")
2local button = script.Parent
3local sound = SoundService:FindFirstChild("SOUND_NAME")
4local function onButtonActivated()
5 if sound then
6 sound:Play()
7 end
8end
9button.Activated:Connect(onButtonActivated)
10