Reference API Roblox

Engine API

Website

Related

Reference API Roblox

Sound

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.

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

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.

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

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.

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. This event is often used to destroy a sound when it has completed playback:

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.

History 2

IsLoaded

TypeDefault
boolfalse

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.

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

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.

History 2

LoopRegion

TypeDefault
NumberRange0 60000

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

History 2

Looped

TypeDefault
boolfalse

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.

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

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

History 3

Paused

Parameters (1)
soundIdstring

Fires whenever the Sound is paused using Pause().

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

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.

History 3

PlayOnRemove

TypeDefault
boolfalse

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

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.

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 and stop time within the TimeLength, in seconds.

History 2

PlaybackRegionsEnabled

TypeDefault
boolfalse

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

History 3

PlaybackSpeed

TypeDefault
float1

Determines the speed at which a Sound will play, with higher values causing the sound to play faster and 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 Play(). This event will not fire if the Sound is played due to PlayOnRemove being set to true and the sound being destroyed.

History 2

Playing

TypeDefault
boolfalse

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.

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

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

History 3

Resumed

Parameters (1)
soundIdstring

Fires when the Sound is resumed using Resume().

History 2

RollOffMaxDistance

TypeDefault
float10000

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.

History 8

RollOffMinDistance

TypeDefault
float10

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.

History 8

RollOffMode

TypeDefault
RollOffModeInverse

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.

History 6

SoundGroup

TypeDefault
SoundGroup

The SoundGroup that is linked to this Sound.

History 6

SoundId

TypeDefault
ContentId

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

History 5

Stop

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

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

History 3

Stopped

Parameters (1)
soundIdstring

Fires when the Sound is stopped through using Stop(). 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 PlaybackSpeed to adjust the speed of a sound so that it lasts for a specific duration.

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

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:

local newPosition = 1.5

if newPosition >= sound.TimeLength then
	newPosition = newPosition - sound.TimeLength
end
sound.TimePosition = newPosition
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 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.

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