Roblox UtilitiesDevlHub Roblox Documentation

Class

Sound

Inherits
Instance › Object
Memory category
Internal

An object that emits sound. This object 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.

Sound is an object that emits sound. When placed in a BasePart or an Attachment, this object will emit its sound from that part's BasePart.Position or the attachment's Attachment.WorldPosition. In this placement, 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. Additionally, its volume 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, see 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.

Properties 25#

AudioContentContentA reference to an audio asset.ReadSafeHidden
EmitterSizefloatThe minimum distance, in studs, at which a 3D Sound (direct child of a BasePart or Attachment) will begin to attenuate (decrease in volume).ReadSafeDeprecated
IsLoadedbooleanThis property is true when the Sound has loaded from Roblox servers and is ready to play.ReadSafeReadOnlyNotReplicated
IsPausedbooleanRead-only property which returns true when the Sound is not playing.ReadSafeHiddenReadOnlyNotReplicated
IsPlayingbooleanRead-only property which returns true when the Sound is playing.ReadSafeHiddenReadOnlyNotReplicated
isPlayingbooleanReadSafeDeprecatedReadOnlyNotReplicated
LoopedbooleanSets whether or not the Sound repeats once it has finished playing.ReadSafe
LoopRegionNumberRangeA range denoting a desired loop start and loop end within the PlaybackRegion, in seconds.ReadSafe
MaxDistancefloatThe maximum distance, in studs, a client's listener can be from the Sound\s origin and still hear it. Only applies to Sounds parented to a Part or Attachment (3D sounds).ReadSafeDeprecated
MinDistancefloatThe minimum distance at which a 3D Sound (direct child of a BasePart or Attachment) will begin to attenuate. Effectively, the emitter size.ReadSafeDeprecated
PitchfloatSets how high pitched and fast a Sound is when it is played. The greater the integer, the higher and faster the Sound is.ReadSafeDeprecated
PlaybackLoudnessdoubleA number between 0 and 1000 indicating how loud the Sound is currently playing back.ReadSafeReadOnlyNotReplicated
PlaybackRegionNumberRangeA range denoting a desired start and stop time within the TimeLength, in seconds.ReadSafe
PlaybackRegionsEnabledbooleanIf true, this property gives your Sound access to the PlaybackRegion and LoopRegion properties which can more-accurately control its playback.ReadSafe
PlaybackSpeedfloatDetermines the speed at which a Sound will play, with higher values causing the sound to play faster and at a higher pitch.ReadSafeNotReplicated
PlayingbooleanIndicates whether the Sound is currently playing.ReadSafeNotReplicated
PlayOnRemovebooleanWhen true, the Sound will play when it is removed from the experience.ReadSafe
RollOffMaxDistancefloatThe maximum distance, in studs, a client's listener can be from the sound's origin and still hear it. Only applies to Sounds parented to a BasePart or Attachment.ReadSafe
RollOffMinDistancefloatThe minimum distance, in studs, at which a Sound which is parented to a BasePart or Attachment will begin to attenuate (decrease in volume).ReadSafe
RollOffModeRollOffModeControls how the volume of a Sound which is parented to a BasePart or Attachment attenuates (fades out) as the distance between the listener and parent changes.ReadSafe
SoundGroupSoundGroupThe SoundGroup that is linked to this Sound.ReadSafe
SoundIdContentIdContent ID of the sound file to associate with the Sound.ReadSafe
TimeLengthdoubleThe length of the Sound in seconds.ReadSafeReadOnlyNotReplicated
TimePositiondoubleProgress of the Sound in seconds. Can be changed to move the playback position of the Sound both before and during playback.ReadSafeNotReplicated
VolumefloatThe volume of the Sound.ReadSafe

AudioContent: Content#

HiddenReadSafe

This property is a reference to an audio asset.

EmitterSize: float#

DeprecatedReadSafeDeprecated

Deprecated. This property has deprecated in favor of Sound.RollOffMinDistance and Sound.RollOffMaxDistance which should be used instead in new work.

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.

IsLoaded: boolean#

ReadOnlyNotReplicatedReadSafe

This property is true when the Sound has loaded from Roblox servers and is ready to play. You can use this property and the Loaded event to verify a sound has loaded before playing it.

IsPaused: boolean#

HiddenReadOnlyNotReplicatedReadSafe

This read-only property returns true when the Sound is not playing. Note that it can return true if a sound has been paused using Pause(), if it has been stopped using Stop(), or the sound has never been played.

As IsPaused is read-only, it cannot be used to stop the sound; Stop() or Pause() should be used instead.

IsPlaying: boolean#

HiddenReadOnlyNotReplicatedReadSafe

This read-only property returns true when the Sound is playing.

As IsPlaying is read-only, it cannot be used to play the sound; Play() should be used instead.

isPlaying: boolean#

ReadOnlyNotReplicatedDeprecatedReadSafeDeprecated

Deprecated. This deprecated property is a variant of Sound.IsPlaying which should be used instead.

Looped: boolean#

ReadSafe

This sets whether or not the Sound repeats once it has finished playing. Looped sounds are suitable for a range of applications including music and background ambient sounds.

The DidLoop event can be used to track the number of times as sound has looped.

LoopRegion: NumberRange#

ReadSafe

A range denoting a desired loop start and loop end within the PlaybackRegion, in seconds.

MaxDistance: float#

DeprecatedReadSafeDeprecated

Deprecated. This property has deprecated in favor of Sound.RollOffMinDistance and Sound.RollOffMaxDistance which should be used instead in new work.

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.

MinDistance: float#

DeprecatedReadSafeDeprecated

Deprecated. MinDistance has been superseded by Sound.EmitterSize, whose name better describes this properties behavior.

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

Pitch: float#

DeprecatedReadSafeDeprecated

Deprecated. This property has been deprecated in favor of Sound.PlaybackSpeed whose name suits the behavior better.

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

PlaybackLoudness: double#

ReadOnlyNotReplicatedReadSafe

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.

PlaybackRegion: NumberRange#

ReadSafe

A range denoting a desired start and stop time within the TimeLength, in seconds.

PlaybackRegionsEnabled: boolean#

ReadSafe

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

PlaybackSpeed: float#

NotReplicatedReadSafe

Determines the speed at which a Sound will play, with higher values causing the sound to play faster and at a higher pitch.

Playing: boolean#

NotReplicatedReadSafe

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

In Studio's Properties window, while in Edit mode, toggling Playing to true does not begin playing the sound, but the sound will begin playing during runtime.

This property should not be confused with IsPlaying which is a read-only property.

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

PlayOnRemove: boolean#

ReadSafe

When true, the Sound will play when it is removed from the experience by parenting the Sound or one if its ancestors to nil. This means all of the following will cause the sound to play when PlayOnRemove is true:

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

RollOffMaxDistance: float#

ReadSafe

The maximum distance, in studs, a client's listener can be from the sound's origin and still hear it. Only applies to Sounds parented to a BasePart or Attachment.

How RollOffMaxDistance impacts the attenuation of a sound (manner in which it fades out) is dependent on the RollOffMode property.

RollOffMinDistance: float#

ReadSafe

The minimum distance, in studs, at which a Sound which is parented to a BasePart or Attachment will begin to attenuate (decrease in volume).

How RollOffMinDistance impacts the attenuation of a sound (manner in which it fades out) is dependent on the RollOffMode property.

RollOffMode: RollOffMode#

ReadSafe

This property controls how the volume of a Sound which is parented to a BasePart or Attachment attenuates (fades out) as the distance between the listener and parent changes.

For details on the different modes, see RollOffMode.

SoundGroup: SoundGroup#

ReadSafe

The SoundGroup that is linked to this Sound.

SoundId: ContentId#

ReadSafe

This property is the content ID of the sound file to associate with the Sound. See Audio Assets for more information.

TimeLength: double#

ReadOnlyNotReplicatedReadSafe

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 PlaybackSpeed to adjust the speed of a sound so that it lasts for a specific duration.

TimePosition: double#

NotReplicatedReadSafe

This property reflects the progress of the Sound in seconds. It can be changed to move the playback position of the sound both before and during playback.

As a Sound is played, TimePosition increases at a rate of PlaybackSpeed per second. Once TimePosition reaches TimeLength, the sound will stop unless it is Looped.

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, consider the following code snippet:

Volume: float#

ReadSafe

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

Note that if the Sound is a member of a SoundGroup, its playback volume (but not its Volume property) will be influenced by the group's SoundGroup.Volume property.

Methods 7#

PausePauses playback of the Sound if it is playing.
pauseDeprecated
PlayPlays the Sound.
playDeprecated
ResumeResumes the Sound.
StopStops the Sound.
stopDeprecated

Pause(): ()#

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

Returns
  • ()

pause(): ()#

DeprecatedDeprecated

Deprecated. This deprecated function is a variant of Sound:Pause() which should be used instead.

Returns
  • ()

Play(): ()#

This method plays the Sound and sets TimePosition to the last value set by a script (or 0 if it has not been set), then sets Playing to true.

Returns
  • ()

play(): ()#

DeprecatedDeprecated

Deprecated. This deprecated function is a variant of Sound:Play() which should be used instead.

Returns
  • ()

Resume(): ()#

This method resumes the Sound and sets Playing to true. Does not alter TimePosition and thus can be used to resume playback of a sound paused through Pause().

Returns
  • ()

Stop(): ()#

This method stops the Sound and sets Playing to false, then sets TimePosition to 0.

Returns
  • ()

stop(): ()#

DeprecatedDeprecated

Deprecated. This deprecated function is a variant of Sound:Stop() which should be used instead.

Returns
  • ()

Events 7#

DidLoopFires whenever the Sound loops.
EndedFires when the Sound has completed playback and stopped.
LoadedFires when the Sound is loaded.
PausedFires whenever the Sound is paused using Pause().
PlayedFires whenever the Sound is played using Play().
ResumedFires when the Sound is resumed using Resume().
StoppedFires when the Sound is stopped through using Stop().

DidLoop(soundId: string, numOfTimesLooped: int)#

Fires whenever the Sound loops. Returns soundId and numOfTimesLooped, giving the content ID of the sound and the number of times looped respectively.

When the Sound is stopped through Stop(), the looped counter resets meaning the next DidLoop event will return 1 for numOfTimesLooped.

NameTypeDefaultDescription
soundIdstringThe SoundId of the Sound that looped.
numOfTimesLoopedintThe number of times the Sound has looped.

Ended(soundId: string)#

Fires when the Sound has completed playback and stopped. This event is often used to destroy a sound when it has completed playback:

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

Note that this event will not fire for sounds with Looped set to true, as they continue playing upon reaching their end. This event will also not fire when the sound is stopped before playback has completed; for this use the Stopped event.

NameTypeDefaultDescription
soundIdstringThe SoundId of the Sound that has ended.

Loaded(soundId: string)#

Fires when the Sound is loaded.

As this event only fires at the time the sound is loaded, it's recommended to check the sound's IsLoaded property prior to connecting to this event.

NameTypeDefaultDescription
soundIdstringThe SoundId of the Sound that loaded.

Paused(soundId: string)#

Fires whenever the Sound is paused using Pause().

NameTypeDefaultDescription
soundIdstringThe SoundId of the Sound that was paused.

Played(soundId: string)#

Fires whenever the Sound is played using Play(). This event will not fire if the Sound is played due to PlayOnRemove being set to true and the sound being destroyed.

NameTypeDefaultDescription
soundIdstringThe SoundId of the Sound that was played.

Resumed(soundId: string)#

Fires when the Sound is resumed using Resume().

NameTypeDefaultDescription
soundIdstringThe SoundId of the Sound being resumed.

Stopped(soundId: string)#

Fires when the Sound is stopped through using Stop(). Destroying a sound while it is playing will not cause this event to fire.

NameTypeDefaultDescription
soundIdstringThe SoundId of the Sound that stopped.

Inherited members#

Inherited from Instance 58
Inherited from Object 6
Properties (2)

ClassName, className

Events (1)

Changed