Open Asterune
Sound

Sound

Plays audio with positional or non-positional output.

Creatable
Instance.new("Sound")
Inherits
Instance
Replication
Standard

Behavior

Sound plays the clip identified by Asset. A sound parented to a part is positional and attenuates with distance. A sound under SoundService or ScreenGui is non-positional.

Destroy temporary sounds after playback. Debris:AddItem currently accepts parts only.

Summary

Members25
Properties12
Methods8
  • CreateStream(sampleRate: number?, channels: number?): AudioStreamserial only

    Creates an AudioStream for queued PCM playback by this Sound.

  • Returns this instance if it is an ExecutionGroup.

  • Pause(): ()serial only

    Pauses playback and retains PlaybackPosition.

  • Play(): ()serial only

    Starts playback from position 0.

  • PlayAt(audioTime: number): ()serial only

    Plays the sound at the supplied audio-clock time.

  • Resume(): ()serial only

    Continues paused playback from the retained position.

  • SetPcm(samples: (buffer | { number })?, sampleRate: number?, channels: number?): ()serial only

    Replaces the sound's audio with PCM samples.

  • Stop(): ()serial only

    Stops playback and resets PlaybackPosition to the beginning.

Events5
  • DidLoop: RBXScriptSignalparallel read

    Fires when a looping sound reaches its end and starts the next loop.

  • Ended: RBXScriptSignalparallel read

    Fires when a non-looping clip reaches the end.

  • Paused: RBXScriptSignalparallel read

    Fires when playback is paused.

  • Played: RBXScriptSignalparallel read

    Fires when playback starts.

  • Stopped: RBXScriptSignalparallel read

    Fires when playback is stopped.

Properties

Asset

Sound.Asset: Content = ""

The audio asset identifier. Assignment resets the cached Duration to 0 until the new asset is loaded.

Duration

Sound.Duration: number = 0

The clip duration in seconds. Returns 0 until the asset has loaded.

Looped

Sound.Looped: boolean = false

Whether the sound restarts after reaching its end.

PlayOnRemove

Sound.PlayOnRemove: boolean

Whether the sound plays when removed from the hierarchy.

PlaybackPosition

Sound.PlaybackPosition: number = 0

The current playback position in seconds. Assignment seeks and clamps negative values to 0. Play resets it to 0.

PlaybackSpeed

Sound.PlaybackSpeed: number = 1

The nonnegative playback rate multiplier. A value of 2 doubles playback rate and halves duration. Playback rate also affects pitch.

Playing

Sound.Playing: boolean = false

Whether the clip is playing. Returns false while paused.

RollOffMode

The attenuation curve between RolloffMinDistance and RolloffMaxDistance. See Enum.RollOffMode.

RolloffMaxDistance

Sound.RolloffMaxDistance: number = 100

The maximum audible distance for positional audio, in studs. Values below RolloffMinDistance are clamped to that minimum.

RolloffMinDistance

Sound.RolloffMinDistance: number = 10

The full-volume distance for positional audio, in studs. Assignment clamps to at least 0 and raises RolloffMaxDistance if necessary.

SoundGroup

Sound.SoundGroup: SoundGroup? = nil

The SoundGroup whose volume multiplier applies to this sound.

Volume

Sound.Volume: number = 0.5

The playback volume multiplier, clamped to 0 through 10. A value of 1 uses the clip level. Higher values can cause clipping.

Methods

CreateStream

Sound:CreateStream(sampleRate: number?, channels: number?): AudioStream

Creates an AudioStream for queued PCM playback by this Sound.

GetExecutionGroup

Sound:GetExecutionGroup(): ExecutionGroup?

Returns this instance if it is an ExecutionGroup. Otherwise returns the nearest ancestor ExecutionGroup, or nil when no group contains the instance.

Pause

Sound:Pause(): ()

Pauses playback and retains PlaybackPosition. Call Resume to continue.

Play

Sound:Play(): ()

Starts playback from position 0. Calling during playback restarts the clip. To resume a paused clip without resetting its position, call Resume.

PlayAt

Sound:PlayAt(audioTime: number): ()

Plays the sound at the supplied audio-clock time.

Resume

Sound:Resume(): ()

Continues paused playback from the retained position.

SetPcm

Sound:SetPcm(samples: (buffer | { number })?, sampleRate: number?, channels: number?): ()

Replaces the sound's audio with PCM samples. Accepts a buffer of little-endian 32-bit floats or an array of numbers, with sample rate and channel count.

Stop

Sound:Stop(): ()

Stops playback and resets PlaybackPosition to the beginning.

Events

DidLoop

Sound.DidLoop: RBXScriptSignal

Fires when a looping sound reaches its end and starts the next loop.

Ended

Sound.Ended: RBXScriptSignal

Fires when a non-looping clip reaches the end. Looping playback does not fire this event.

Paused

Sound.Paused: RBXScriptSignal

Fires when playback is paused.

Played

Sound.Played: RBXScriptSignal

Fires when playback starts.

Stopped

Sound.Stopped: RBXScriptSignal

Fires when playback is stopped.

Inherited members

Inherited47

Example

Luau
local sound = Instance.new("Sound")
sound.Asset = "rbxassetid://9120386436"
sound.Parent = game:GetService("SoundService")
sound:Play()

SoundService · Debris · Enum.RollOffMode