Skip to content

Audio Source Component

Berke edited this page Jun 23, 2026 · 1 revision

AudioSource

The AudioSource component controls 3D spatial audio playback and sound properties.


Properties

isValid

audio.isValid

Returns whether the component is still valid.

Returns

boolean

name

audio.name

Returns the internal name of the audio source.

Returns

string

soundIndex

audio.soundIndex

Gets or sets the currently assigned sound.

Returns

number

Example

audio.soundIndex = 2

pitch

audio.pitch

Controls playback pitch.

Returns

number

Example

audio.pitch = 1.2

gain

audio.gain

Controls volume (gain).

Returns

number

Example

audio.gain = 0.5

looping

audio.looping

Enables or disables looping playback.

Returns

boolean

playOnStart

audio.playOnStart

If true, sound plays automatically when the scene starts.

Returns

boolean

referenceDistance

audio.referenceDistance

Distance at which the sound starts attenuating.

Returns

number

maxDistance

audio.maxDistance

Maximum distance the sound can be heard.

Returns

number

rollOffFactor

audio.rollOffFactor

Controls how quickly sound attenuates with distance.

Returns

number

innerConeAngle

audio.innerConeAngle

Inner angle of directional sound cone.

Returns

number

outerConeAngle

audio.outerConeAngle

Outer angle of directional sound cone.

Returns

number

outerGain

audio.outerGain

Volume outside the outer cone.

Returns

number

Methods

play

audio:play()

Plays the assigned sound.

Returns

nil

setSourcePosition

audio:setSourcePosition(position)

Sets the world position of the audio source.

Parameters

Name Type Description
position Vector3 World position of sound source

Returns

nil

Example

local audio = entity.audioSource

audio.gain = 0.8
audio.pitch = 1.1
audio.looping = true

audio:play()

Clone this wiki locally