Loading...
Loading...
Sound and music - the Audio API (AudioPlayer, AudioEmitter, AudioListener, AudioDeviceOutput, Wire, effects, faders), classic Sound/SoundGroup, 2D vs 3D audio, music and SFX volume, client vs server playback, asset permissions, streaming caveats, voice routing, text-to-speech. Use when adding music, sound effects, spatial audio, mixing, or fixing sounds that don't play.
npx skill4agent add el4cteo/roblox-skills roblox-audioAudioPlayerWireAudioEmitterAudioListenerWireAudioDeviceOutputSoundSoundServiceSoundGroupSoundEffect--!strict
-- Client: build a music player once.
local SoundService = game:GetService("SoundService")
local player = Instance.new("AudioPlayer")
player.Name = "Music"
player.Asset = "rbxassetid://1843463175" -- AudioPlayer.AssetId is deprecated; use Asset
player.Looping = true
player.Volume = 0.5
player.Parent = SoundService
local fader = Instance.new("AudioFader") -- one place to control music volume (settings menu)
fader.Name = "MusicVolume"
fader.Parent = SoundService
local output = Instance.new("AudioDeviceOutput")
output.Parent = SoundService
local function wire(source: Instance, target: Instance)
local w = Instance.new("Wire")
w.SourceInstance = source
w.TargetInstance = target
w.Parent = target
end
wire(player, fader)
wire(fader, output)
player:Play()AudioEmitterAudioPlayer → AudioEmitterSoundService.ListenerLocationAudioListenerAudioListener → AudioDeviceOutputAudioEmitter:SetDistanceAttenuationAudioInteractionGroup--!strict
local SoundService = game:GetService("SoundService")
local sfxGroup = Instance.new("SoundGroup")
sfxGroup.Name = "SFX"
sfxGroup.Volume = 0.8
sfxGroup.Parent = SoundService
local function playAt(part: BasePart, soundId: string)
local sound = Instance.new("Sound")
sound.SoundId = soundId
sound.SoundGroup = sfxGroup
sound.RollOffMaxDistance = 80
sound.Parent = part -- 3D: plays from the part; parent to SoundService/UI for 2D
sound:Play()
sound.Ended:Once(function()
sound:Destroy()
end)
end
return playAtSoundService:PlayLocalSound(sound)ContentProvider:PreloadAsync({ sound })SoundService.RespectFilteringEnabled = trueSoundServiceAudioEqualizerAudioCompressorAudioReverbAudioEchoAudioChorusAudioDistortionAudioFlangerAudioPitchShifterAudioTremoloAudioFilterAudioLimiterAudioAnalyzerAudioTextToSpeechAudioSpeechToTextAudioDeviceInputroblox-uiroblox-architectureroblox-performance