Skip to content

Audio

System · Audio · server and client scripts

Audio plays one-shot 2D and 3D sounds, controls mixer bus volumes, and sets how loud touching parts sound. For a sound that loops or plays from an entity, add a Sound component to the entity instead.

GetBusVolume

FunctionClient only
GetBusVolume(bus: SoundBus) -> number

GetBusVolume returns this client's local volume multiplier (0 to 10) for a mixer bus ("Master", "Music", "SFX", or "UI").

Example

-- Client script.
print(Audio.GetBusVolume("Music")) -- prints 1
Errors (1)
Error When
GetBusVolume can only be called from a client script Called from a server script.

GetPlaceBusVolume

Function
GetPlaceBusVolume(bus: SoundBus) -> number

GetPlaceBusVolume returns the place's shared volume multiplier (0 to 10) for a mixer bus ("Master", "Music", "SFX", or "UI").

Example

-- Server script.
print(Audio.GetPlaceBusVolume("SFX")) -- prints 1

Play

Function
Play(asset: string, options: AudioPlayOptions?) -> boolean

Play plays a one-shot 2D sound. Pass the asset id as a string and an optional AudioPlayOptions table with Volume, PlaybackSpeed, Bus, and, on the server, To.

Returns false when the server already queued 64 sounds this tick, otherwise true.

Example

-- Client script.
local CLICK = "144115188075855954"
Audio.Play(CLICK, { Volume = 0.8, Bus = "UI" })

PlayAt

Function
PlayAt(asset: string, position: Vector3, options: AudioPlayAtOptions?) -> boolean

PlayAt plays a one-shot 3D sound at a world position. Pass the asset id as a string: a number cannot represent every digit of a 64-bit id. Pass an optional AudioPlayAtOptions table as the third argument. The server does not send a cue to players whose character is farther than RollOffMaxDistance (default 200 units) away.

Returns false when the server already queued 64 sounds this tick, otherwise true.

Example

-- Server script in a part.
local CHIME = "144115188075855954"
while true do
    local pos = self.Position
    if pos then
        Audio.PlayAt(CHIME, pos, {
            Volume = 0.8,
            PlaybackSpeed = 1.15,
            RollOffMinDistance = 12,
            RollOffMaxDistance = 300,
            RollOffScale = 1.5,
            Bus = "SFX",
        })
    end
    task.wait(2)
end

SetBusVolume

FunctionClient only
SetBusVolume(bus: SoundBus, volume: number) -> ()

SetBusVolume sets this client's local volume multiplier (0 to 10) for a mixer bus ("Master", "Music", "SFX", or "UI").

Example

-- Client script: lower the music volume locally.
Audio.SetBusVolume("Music", 0.5)
print(Audio.GetBusVolume("Music")) -- prints 0.5
Errors (1)
Error When
SetBusVolume can only be called from a client script Called from a server script.

SetPlaceBusVolume

FunctionServer only
SetPlaceBusVolume(bus: SoundBus, volume: number) -> ()

SetPlaceBusVolume sets the place's shared volume multiplier (0 to 10) for a mixer bus ("Master", "Music", "SFX", or "UI"). Only server scripts may call it.

Example

-- Server script: lower place SFX volume.
Audio.SetPlaceBusVolume("SFX", 0.6)
print(Audio.GetPlaceBusVolume("SFX")) -- prints 0.6
Errors (1)
Error When
SetPlaceBusVolume can only be called from the server Called from a client script.

SurfaceSoundsVolume

PropertyServer only
SurfaceSoundsVolume: number

SurfaceSoundsVolume is the volume multiplier of the impact and sliding sounds of touching parts, from 0 (silent) to 10.

Default 1

Errors (1)
Error When
SurfaceSoundsVolume can only be written from the server Written from a client script.