Reference API Roblox

Engine API

Website

Related

Reference API Roblox

Sound

A Sound is an object that emits sound. Sounds can be placed within a BasePart or Attachment to emit a sound from a particular position within a place or world, or it can be attached elsewhere to play the sound at a constant volume throughout the entire place.

Member index 51

HistoryMember
553ChannelCount: int
648EmitterSize: float
553IsLoaded: bool
553LoopRegion: NumberRange
553Looped: bool
601MaxDistance: float
601MinDistance: float
553Pitch: float
553PlayOnRemove: bool
553PlaybackLoudness: double
553PlaybackRegion: NumberRange
582PlaybackRegionsEnabled: bool
553PlaybackSpeed: float
553Playing: bool
648RollOffMaxDistance: float
648RollOffMinDistance: float
553RollOffMode: RollOffMode
553SoundGroup: SoundGroup
645SoundId: ContentId
553TimeLength: double
553TimePosition: double
553Volume: float
553isPlaying: bool
573Pause(): null
573Play(): null
573Resume(): null
573Stop(): null
573pause(): null
573play(): null
573stop(): null
462DidLoop(soundId: string, numOfTimesLooped: int)
462Ended(soundId: string)
462Loaded(soundId: string)
462Paused(soundId: string)
462Played(soundId: string)
462Resumed(soundId: string)
462Stopped(soundId: string)
inherited from Instance
553Archivable: bool
635Capabilities: SecurityCapabilities
553Name: string
553Parent: Instance
635Sandboxed: bool
616UniqueId: UniqueId
576AddTag(tag: string): null
573ClearAllChildren(): null
462Clone(): Instance
573Destroy(): null
486FindFirstAncestor(name: string): Instance
486FindFirstAncestorOfClass(className: string): Instance
486FindFirstAncestorWhichIsA(className: string): Instance
486FindFirstChild(name: string, recursive: bool = false): Instance
486FindFirstChildOfClass(className: string): Instance
486FindFirstChildWhichIsA(className: string, recursive: bool = false): Instance
486FindFirstDescendant(name: string): Instance
563GetActor(): Actor
486GetAttribute(attribute: string): Variant
462GetAttributeChangedSignal(attribute: string): RBXScriptSignal
631GetAttributes(): Dictionary
648GetChildren(): Instances
462GetDebugId(scopeLength: int = 4): string
486GetDescendants(): Array
486GetFullName(): string
641GetStyled(name: string): Variant
576GetTags(): Array
576HasTag(tag: string): bool
486IsAncestorOf(descendant: Instance): bool
486IsDescendantOf(ancestor: Instance): bool
580IsPropertyModified(name: string): bool
573Remove(): null
576RemoveTag(tag: string): null
580ResetPropertyToDefault(name: string): null
573SetAttribute(attribute: string, value: Variant): null
462WaitForChild(childName: string, timeOut: double): Instance
648children(): Instances
553clone(): Instance
573destroy(): null
553findFirstChild(name: string, recursive: bool = false): Instance
648getChildren(): Instances
553isDescendantOf(ancestor: Instance): bool
573remove(): null
462AncestryChanged(child: Instance, parent: Instance)
462AttributeChanged(attribute: string)
462ChildAdded(child: Instance)
462ChildRemoved(child: Instance)
462DescendantAdded(descendant: Instance)
462DescendantRemoving(descendant: Instance)
500Destroying()
553childAdded(child: Instance)
inherited from Object
647ClassName: string
647className: string
647GetPropertyChangedSignal(property: string): RBXScriptSignal
647IsA(className: string): bool
650isA(className: string): bool
647Changed(property: string)

Description

A Sound is an object that emits sound.

2D and 3D Sound

A sound placed in a BasePart or an Attachment will emit its sound from that part's BasePart.Position or the attachment's Attachment.WorldPosition. A sound exhibits the Doppler effect, meaning its frequency and pitch varies with the relative motion of whatever attachment or part it is attached to. The volume of the sound will be determined by the distance between the client's sound listener (by default the Camera position) and the position of the sound's parent. For more information on this see Sound.RollOffMode.

A sound is considered "global" if it is not parented to a BasePart or an Attachment. In this case, the sound will play at the same volume throughout the entire place.

History 203

Members 51

ChannelCount

TypeDefault
int0
This property is not replicated. Its interface does not cross the network boundary.
This property is read-only. Its value can be read, but it cannot be modified.
This property is not browsable. It is not visible in Studio's object browser.

History 3

Tags: [ReadOnly, NotReplicated, NotBrowsable]

DidLoop

Parameters (2)
soundIdstring
numOfTimesLoopedint

Event that fires whenever the Sound loops. Returns soundId and numOfTimesLooped, giving the contentID of the sound and the number of times looped respectively.

When the Sound is stopped the looped counter resets meaning the next DidLoop event will return 1 for numOfTimesLooped.

History 2

EmitterSize

TypeDefault
float10

The minimum distance, in studs, at which a 3D Sound (direct child of a BasePart or Attachment) will begin to attenuate (decrease in volume).

Sounds parented to a BasePart or Attachment that are descendants of the Workspace are considered 3D sounds and their volume while playing is dependent on the distance between the client's sound listener (Camera position by default) and the Sound's parent. Two properties influence this behavior EmitterSize and Sound.RollOffMode.

The way the Sound attenuates (fades out) after the distance between the listener and the sound exceeds the EmitterSize is determined by RollOffMode.

This property is deprecated. It exists only for backward compatibility, and should not be used for new work. RollOffMinDistance should be used instead.

History 11

Tags: [Deprecated]

Ended

Parameters (1)
soundIdstring

Fires when the Sound has completed playback and stopped. Note this event will not fire for sounds with Sound.Looped set to true as they continue playing upon reaching their end.

This event is often used to destroy a sound when it has completed playback.

sound:Play()
sound.Ended:Wait()
sound:Destroy()

This event only fires if the sound has reached its end. This means it will also not fire when the sound is stopped before playback has completed, for this use Sound.Stopped.

History 2

IsLoaded

TypeDefault
boolfalse

This property will be true when the Sound has loaded from Roblox servers and is ready to play.

In Roblox, audio files are not stored in games themselves but hosted on the Roblox servers and referenced by the Sound.SoundId property. This means that they need to be downloaded to a client's device before they can be played. This can take a while depending on the user's internet connection, the length of the sound and the number of other objects that need to be loaded.

Developers can use the Sound.IsLoaded property and the Sound.Loaded event if they wish to verify a sound has loaded before playing it.

This property is not replicated. Its interface does not cross the network boundary.
This property is read-only. Its value can be read, but it cannot be modified.

History 5

Tags: [ReadOnly, NotReplicated]

Loaded

Parameters (1)
soundIdstring

The Sound.Loaded event fires when the Sound is loaded.

Note this event will only fire at the time the sound is loaded. This means if it is listened for when the sound is already loaded it will not return. Therefore it is recommended to check Sound.IsLoaded prior to connecting to this event.

History 2

LoopRegion

TypeDefault
NumberRange0 60000

A range denoting a desired loop-start and loop-end within the Sound's Sound.PlaybackRegion in seconds.

History 2

Looped

TypeDefault
boolfalse

This sets whether or not the Sound repeats once it has finished when it is playing.

Looped sounds are suitable for a range of applications including music and background ambient sounds. The Sound.DidLoop event can be used to track the number of times as sound has looped.

History 5

MaxDistance

TypeDefault
float10000

The maximum distance, in studs, a client's listener can be from the Sound origin and still hear it. Only applies to Sounds parented to a Part or Attachment (3D sounds).

How MaxDistance impacts the attenuation of a sound (manner in which it fades out) is dependent on the Sound.RollOffMode property. When RollOffMode is set to use an inverse type distance model (Inverse or InverseTapered) the MaxDistance will not effect the attenuation of the sound. This means that low values for MaxDistance will cause the sound to abruptly cut off when the listener reaches the MaxDistance. In most cases this is not desirable and developers are advised not to use low MaxDistance values.

When RollOffMode is set to a linear type distance model (Linear or LinearSquared) the sound will attenuate between Sound.EmitterSize and MaxDistance (with playback volume reaching zero at MaxDistance). This is less realistic, but in some cases allows attenuation to be handled in a more intuitive way.

This property is deprecated. It exists only for backward compatibility, and should not be used for new work. RollOffMaxDistance should be used instead.

History 10

Tags: [Deprecated]

MinDistance

TypeDefault
float10

The minimum distance at which a 3D Sound (direct child of a BasePart or Attachment) will begin to attenuate. Effectively, the emitter size.

This property is deprecated. It exists only for backward compatibility, and should not be used for new work. RollOffMinDistance should be used instead.

History 10

Tags: [Deprecated]

Pause

Parameters (0)
No parameters.
Returns (1)
null

Sets Sound.Playing to false. This pauses the playback of the Sound if the sound is playing. Unlike Sound:Stop() it does not reset Sound.TimePosition meaning the sound can be resumed using Sound:Resume().

The impact of the different Sound functions on Sound.Playing and Sound.TimePosition are shown below.

FunctionSound.PlayingSound.TimePosition
Sound:Play()TrueLast value set in Lua (default 0)
Sound:Pause()False-
Sound:Resume()True-
Sound:Stop()False0

History 3

Paused

Parameters (1)
soundIdstring

Fires whenever the Sound is paused using Sound:Pause().

As with Sound.Played, Sound.Resumed and Sound.Stopped only the respective sound function will cause the event to fire. This means that Pause will only fire when Sound:Pause() is called.

History 2

Pitch

TypeDefault
float1

Sets how high pitched and fast a Sound is when it is played. The greater the integer, the higher and faster the sound is.

This property is deprecated. It exists only for backward compatibility, and should not be used for new work. PlaybackSpeed should be used instead.

History 6

  • 553 Change PreferredDescriptor of Pitch from to PlaybackSpeed
  • 553 Change Default of Pitch from to 1
  • 486 Change ThreadSafety of Pitch from ReadOnly to ReadSafe
  • 462 Change ThreadSafety of Pitch from to ReadOnly
  • 262 Change Tags of Pitch from [] to [Deprecated]
  • 47 Add Pitch
Tags: [Deprecated]

Play

Parameters (0)
No parameters.
Returns (1)
null

Plays the Sound. Sets Sound.TimePosition to the last value set by a Script (or 0 if it has not been set), and then sets Sound.Playing to true.

The impact of the different Sound functions on Sound.Playing and Sound.TimePosition are shown below.

FunctionSound.PlayingSound.TimePosition
Sound:Play()TrueLast value set in Lua (default 0)
Sound:Pause()False-
Sound:Resume()True-
Sound:Stop()False0

History 3

PlayOnRemove

TypeDefault
boolfalse

When true, the Sound will play when it is removed from the game.

Note the sound will play when the Instance.Parent property of the Sound or one of its ancestors is set to nil. This means all of the following will cause the sound to play when PlayOnRemove is true. Note, this includes Instance:Destroy() as the destroy function sets the parent to nil.

sound:Destroy()
sound.Parent = nil
sound.Parent.Parent = nil

History 4

PlaybackLoudness

TypeDefault
double0

A number between 0 and 1000 indicating how loud the Sound is currently playing back.

This property reflects the amplitude of the sound's playback in the instance of time it is read. Therefore, for most sounds it will fluctuate constantly. Due to this it can appear in the Roblox Studio properties window as 0, however when read by code in the command bar or Scripts it will return the correct value.

This property is not replicated. Its interface does not cross the network boundary.
This property is read-only. Its value can be read, but it cannot be modified.

History 5

Tags: [ReadOnly, NotReplicated]

PlaybackRegion

TypeDefault
NumberRange0 60000

A range denoting a desired start (min) and stop (max) time within the Sound.TimeLength, in seconds.

  • If PlaybackRegion.Min > 0, the sound begins to play from the PlaybackRegion.Min time.

  • If PlaybackRegion.Min < 0, the sound begins to play from 0.

  • If PlaybackRegion.Max > Sound.TimeLength, the sound stops at Sound.TimeLength.

  • If PlaybackRegion.Max < Sound.TimeLength, the sound stops at exactly that time.

  • If PlaybackRegion.Min == PlaybackRegion.Max, the PlayBackRegion is inactive.

History 2

PlaybackRegionsEnabled

TypeDefault
boolfalse

If true, this property gives your Sound access to the Sound.PlaybackRegion and Sound.LoopRegion properties, which can more-accurately control its playback.

History 3

PlaybackSpeed

TypeDefault
float1

Determines the speed at which a Sound will play. The greater the value the faster the sound will play back.

For example, a value of 2 will cause the Sound to play 2x faster, whereas a value of 0.5 will cause it to play 2x slower. When PlaybackSpeed is equal to 1, the sound will take Sound.TimeLength (in seconds) to complete.

Note that increasing the PlaybackSpeed of a sound will cause it to play at a higher pitch.

This property is not replicated. Its interface does not cross the network boundary.

History 6

Tags: [NotReplicated]

Played

Parameters (1)
soundIdstring

Fires whenever the Sound is played using the Sound:Play() function.

As with Sound.Stopped, Sound.Paused and Sound.Resumed only the respective sound function will cause the event to fire. This means that Played will only fire when Sound:Play() is called. This event will not fire if the Sound is played due to the sound being destroyed and Sound.PlayOnRemove being set to true.

History 2

Playing

TypeDefault
boolfalse

Indicates whether the Sound is currently playing. This can be toggled, and this property will always replicate.

In the studio editor, Sounds are not playable because time is halted. Setting Sound.Playing to true in edit mode doesn't do anything. However, you can play audio from within plugins by setting the Sounds as descendants of a PluginGui.

This property should not be confused with Sound.IsPlaying which is a read-only property. Playing can be set to true or false to start or stop the playback of a sound.

Note that when Playing is set to false, the Sound.TimePosition property of the sound will not reset. This means when the Playing is set to true again the audio will continue from the time position it was at when it was stopped. However, if the Sound:Play() function is used to resume the sound the time position will reset to 0.

This property is not replicated. Its interface does not cross the network boundary.

History 6

Tags: [NotReplicated]

Resume

Parameters (0)
No parameters.
Returns (1)
null

Resumes the Sound. Sets Sound.Playing to true. Does not alter Sound.TimePosition and thus can be used to resume the playback of a sound stopped using Sound:Pause().

The impact of the different sound functions on Sound.Playing and Sound.TimePosition are shown below.

FunctionSound.PlayingSound.TimePosition
Sound:Play()TrueLast value set in Lua (default 0)
Sound:Pause()False-
Sound:Resume()True-
Sound:Stop()False0

History 3

Resumed

Parameters (1)
soundIdstring

Fires when the Sound is resumed using Sound:Resume().

As with Sound.Played, Sound.Paused and Sound.Stopped only the respective sound function will cause the event to fire. This means that Resumed will only fire when Sound:Resume() is called.

History 2

RollOffMaxDistance

TypeDefault
float10000

The maximum distance, in studs, a client's listener can be from the Sound origin and still hear it. Only applies to Sounds parented to a Part or Attachment (3D sounds).

How RollOffMaxDistance impacts the attenuation of a sound (manner in which it fades out) is dependent on the Sound.RollOffMode property. When RollOffMode is set to use an inverse type distance model (Inverse or InverseTapered) the RollOffMaxDistance will not effect the attenuation of the sound. This means that low values for RollOffMaxDistance will cause the sound to abruptly cut off when the listener reaches the RollOffMaxDistance. In most cases this is not desirable and developers are advised not to use low RollOffMaxDistance values.

When RollOffMode is set to a linear type distance model (Linear or LinearSquared) the sound will attenuate between Sound.EmitterSize and MaxDistance (with playback volume reaching zero at RollOffMaxDistance). This is less realistic, but in some cases allows attenuation to be handled in a more intuitive way.

History 8

RollOffMinDistance

TypeDefault
float10

The minimum distance, in studs, at which a 3D Sound (direct child of a BasePart or Attachment) will begin to attenuate (decrease in volume).

Sounds parented to a BasePart or Attachment that are descendants of the Workspace are considered 3D sounds and their volume while playing is dependent on the distance between the client's sound listener (Camera position by default) and the Sound's parent. Three properties influence this behavior RollOffMinDistance, Sound.RollOffMaxDistance, and Sound.RollOffMode.

The way the Sound attenuates (fades out) after the distance between the listener and the sound exceeds the RollOffMinDistance is determined by the RollOffMode.

History 8

RollOffMode

TypeDefault
RollOffModeInverse

This property sets how 3D Sounds attenuate (fade out) as the distance between the listener and the sound's parent increase. It can be set to one of the values of the RollOffMode enum.

The following code will set RollOffMode to Linear:

1
sound.RollOffMode = Enum.RollOffMode.Linear

The different modes

The following options are available:

ModeDescription
InverseVolume attenuates from Sound/RollOffMinDistance in an inverse manner.
InverseTaperedA hybrid model. Follows the Inverse model when close to RollOffMinDistance and the Linear Square model when close to Sound/RollOffMaxDistance.
LinearVolume attenuates between RollOffMinDistance and Sound/RollOffMaxDistance with a linear relationship.
LinearSquareVolume attenuates between RollOffMinDistance and Sound/RollOffMaxDistance with a linear squared relationship.

Inverse vs Linear Distance Attenuation

By default sounds are set to use inverse distance attenuation (Enum.RollOffMode.Inverse) which mirrors how sounds attenuate in the real world. Under inverse distance attenuation, sounds will begin to attenuate once the distance between the listener and the Sound's parent exceeds RollOffMinDistance. The rate of attenuation depends on the emitter size, as sounds with larger EmitterSize's will attenuate at a slower rate. Inverse rate of inverse distance attenuation is further influenced by SoundService.RolloffScale.

RollOffMaxDistance will not effect attenuation under the inverse model but will cause the sound to cut off completely once this distance is reached. This can be particularly abrupt when using low values for max distance.

Linear distance attenuation works differently. Under linear distance attenuation the sound will attenuate between RollOffMinDistance and RollOffMaxDistance, falling silent once MaxDistance is reached. RollOffMinDistance still denotes the point at which the sound will begin attenuating. However, the audible volume at any point now depends on the point the listener is at between EmitterSize and MaxDistance. This means, in contrast to the inverse distance attenuation model, the audible volume of the sound will approach silence at MaxDistance point. This is less realistic, but may be more desirable in some cases.

History 6

SoundGroup

TypeDefault
SoundGroup

The SoundGroup that is linked to this Sound. SoundGroup.Volume and SoundEffects applied to this sound group will pass onto the sound. A sound can only be in one sound group at a time.

SoundGroups are used to manage the volume and effects of multiple Sounds at once. A Sound is added to a SoundGroup by setting the SoundGroup property of the sound.

History 6

SoundId

TypeDefault
ContentId

This property is the content ID of the sound file a Sound object is associated with. Once a sound has been uploaded to Roblox the content ID can be found in the uploaded sound's URL.

It's important to remember the URL is not the same as the content ID. It will work when pasted directly into the SoundId property of a Sound in Roblox studio, as Studio will automatically correct it, however if it is being set from a Script then the correct content ID will need to be used, using the number from the URL. For example:

1
2
3
"https://www.roblox.com/catalog/9120386436" -- Web URL (will not work)
"http://www.roblox.com/asset/?id=9120386436" -- Content ID (will work)
"rbxassetid://9120386436" -- Content ID (alternative version, will work)

History 5

Stop

Parameters (0)
No parameters.
Returns (1)
null

Stops the Sound. Sets Sound.Playing to false then sets Sound.TimePosition to 0.

The impact of the different sound functions on Sound.Playing and Sound.TimePosition are shown below.

FunctionSound.PlayingSound.TimePosition
Sound:Play()TrueLast value set in Lua (default 0)
Sound:Pause()False-
Sound:Resume()True-
Sound:Stop()False0

History 3

Stopped

Parameters (1)
soundIdstring

Fires when the Sound is stopped due to the Sound:Stop() function.

As with Sound.Played, Sound.Paused and Sound.Resumed only the respective sound function will cause the event to fire. This means that Stopped will only fire when Sound:Stop() is called. Destroying a sound while it is playing will not cause this event to fire.

History 2

TimeLength

TypeDefault
double0

The length of the Sound in seconds. If the Sound is not loaded, this value will be 0.

This property is often used in conjunction with Sound.PlaybackSpeed to adjust the speed of a sound so it lasts for a specific duration (see examples). When Sound.PlaybackSpeed is equal to 1, the sound will take TimeLength seconds to complete.

This property is not replicated. Its interface does not cross the network boundary.
This property is read-only. Its value can be read, but it cannot be modified.

History 6

Tags: [ReadOnly, NotReplicated]

TimePosition

TypeDefault
double0

Shows the progress in seconds of the Sound. Can be changed to move the playback position of the sound. If the sound is already playing then playback will snap to the specified position. If it is not playing the Sound will begin playback at the set position when the sound is next played.

As a Sound is played, TimePosition increases at a rate of Sound.PlaybackSpeed per second. Once TimePosition reaches Sound.TimeLength the Sound will stop unless it is looped. This means, unless Sound.Looped is set to true setting TimePosition to a value equal or greater to Sound.TimeLength will stop the sound.

Note that setting TimePosition to a value greater than the length in a looped track will not cause it to wrap around. If that behavior is desired the developer should do the following.

if newPosition >= sound.TimeLength then
	newPosition = newPosition - sound.TimeLength
end
sound.TimePosition = newPosition

Setting TimePosition to a value less than zero currently does not influence playback, but this behavior should not be relied upon.

This property is not replicated. Its interface does not cross the network boundary.

History 7

Tags: [NotReplicated]

Volume

TypeDefault
float0.5

The volume of the Sound. Can be set between 0 and 10. Defaults to 0.5

Note that if the Sound is a member of a SoundGroup its playback volume (but not the Volume property) will be influenced by the SoundGroup.Volume property of that SoundGroup. The effect of this is multiplicative, meaning that a sound will play at the same volume if its Volume is 0.1 and its SoundGroup volume is 5 and vice-versa.

History 5

isPlaying

TypeDefault
boolfalse
This property is deprecated. It exists only for backward compatibility, and should not be used for new work. should be used instead.
This property is not replicated. Its interface does not cross the network boundary.
This property is read-only. Its value can be read, but it cannot be modified.

History 5

Tags: [ReadOnly, NotReplicated, Deprecated]

pause

Parameters (0)
No parameters.
Returns (1)
null
This function is deprecated. It exists only for backward compatibility, and should not be used for new work. Pause should be used instead.

History 4

Tags: [Deprecated]

play

Parameters (0)
No parameters.
Returns (1)
null
This function is deprecated. It exists only for backward compatibility, and should not be used for new work. Play should be used instead.

History 4

Tags: [Deprecated]

stop

Parameters (0)
No parameters.
Returns (1)
null
This function is deprecated. It exists only for backward compatibility, and should not be used for new work. Stop should be used instead.

History 4

Tags: [Deprecated]

Settings