Aprenda
Classe do mecanismo
Sound

*Este conteúdo é traduzido por IA (Beta) e pode conter erros. Para ver a página em inglês, clique aqui.


Amostras de código
Parte de Música Reproduzindo
local part = Instance.new("Part")
part.Anchored = true
part.Position = Vector3.new(0, 3, 0)
part.BrickColor = BrickColor.new("Bright red")
part.Name = "MusicBox"
part.Parent = workspace
-- criar um som
local sound = Instance.new("Sound", part)
sound.SoundId = "rbxassetid://9120386436"
sound.EmitterSize = 5 -- diminuir o tamanho do emissor (para queda de volume mais cedo)
sound.Looped = true
sound.Parent = part
local clickDetector = Instance.new("ClickDetector")
clickDetector.Parent = part
-- alternar entre som tocando / não tocando
clickDetector.MouseClick:Connect(function()
if not sound.IsPlaying then
part.BrickColor = BrickColor.new("Bright green")
sound:Play()
else
part.BrickColor = BrickColor.new("Bright red")
sound:Stop()
end
end)

Referência API
Propriedades
AcousticSimulationEnabled
Ler Parallel
Recursos: LegacySound
Sound.AcousticSimulationEnabled:boolean

AudioContent
Oculto
Ler Parallel
Recursos: LegacySound
Sound.AudioContent:Content

EmitterSize
Obsoleto

IsLoaded
Somente leitura
Não replicado
Ler Parallel
Recursos: LegacySound
Sound.IsLoaded:boolean
Amostras de código
Carregar Som
local sound = script.Parent.Sound
if not sound.IsLoaded then
sound.Loaded:Wait()
end
print("O som foi carregado!")

IsPaused
Oculto
Somente leitura
Não replicado
Ler Parallel
Recursos: LegacySound
Sound.IsPaused:boolean
Amostras de código
Som EstáTocando e SomEstáPausado
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://9120386436"
sound.Looped = true
sound.Parent = workspace
if not sound.isLoaded then
sound.Loaded:Wait()
end
sound:Play()
print(sound.IsPlaying, sound.IsPaused) -- verdadeiro, falso
task.wait(2)
sound:Pause()
print(sound.IsPlaying, sound.IsPaused) -- falso, verdadeiro
task.wait(2)
sound:Play()
print(sound.IsPlaying, sound.IsPaused) -- verdadeiro, falso
task.wait(2)
sound:Stop()
print(sound.IsPlaying, sound.IsPaused) -- falso, verdadeiro

IsPlaying
Oculto
Somente leitura
Não replicado
Ler Parallel
Recursos: LegacySound
Sound.IsPlaying:boolean
Amostras de código
Som EstáTocando e SomEstáPausado
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://9120386436"
sound.Looped = true
sound.Parent = workspace
if not sound.isLoaded then
sound.Loaded:Wait()
end
sound:Play()
print(sound.IsPlaying, sound.IsPaused) -- verdadeiro, falso
task.wait(2)
sound:Pause()
print(sound.IsPlaying, sound.IsPaused) -- falso, verdadeiro
task.wait(2)
sound:Play()
print(sound.IsPlaying, sound.IsPaused) -- verdadeiro, falso
task.wait(2)
sound:Stop()
print(sound.IsPlaying, sound.IsPaused) -- falso, verdadeiro

isPlaying
Obsoleto

Looped
Ler Parallel
Recursos: LegacySound
Sound.Looped:boolean
Amostras de código
Repetir um Número de Vezes
local function loopNTimes(sound, numberOfLoops)
if not sound.IsPlaying then
sound.Looped = true
local connection = nil
connection = sound.DidLoop:Connect(function(_soundId, numOfTimesLooped)
print(numOfTimesLooped)
if numOfTimesLooped >= numberOfLoops then
-- desconectar a conexão
connection:Disconnect()
-- parar o som
sound:Stop()
end
end)
sound:Play()
end
end
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://0"
loopNTimes(sound, 5)

LoopRegion
Ler Parallel
Recursos: LegacySound
Sound.LoopRegion:NumberRange

MaxDistance
Obsoleto

MinDistance
Obsoleto

Pitch
Obsoleto

PlaybackLoudness
Somente leitura
Não replicado
Ler Parallel
Recursos: LegacySound
Sound.PlaybackLoudness:number
Amostras de código
Barra de Amplitude de Volume
-- a ser colocado em StarterPlayer > StarterPlayerScripts
local Players = game:GetService("Players")
-- aguarde o PlayerGui do jogador local
local LocalPlayer = Players.LocalPlayer
local playerGui = LocalPlayer:WaitForChild("PlayerGui")
-- crie um ScreenGui
local screenGui = Instance.new("ScreenGui")
screenGui.Parent = playerGui
-- crie um suporte para nossa barra
local frame = Instance.new("Frame")
frame.AnchorPoint = Vector2.new(0.5, 0.5)
frame.Position = UDim2.new(0.5, 0, 0.5, 0)
frame.Size = UDim2.new(0.3, 0, 0.05, 0)
frame.Parent = screenGui
-- crie uma barra
local bar = Instance.new("Frame")
bar.Position = UDim2.new(0, 0, 0, 0)
bar.Size = UDim2.new(1, 0, 1, 0)
bar.BackgroundColor3 = Color3.new(0, 1, 0)
bar.Parent = frame
-- crie um som
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://9120386436"
sound.Looped = true
sound.Parent = screenGui
sound:Play()
-- defina um volume máximo
local maxLoudness = 30
-- anime a barra de amplitude
while true do
local amplitude = math.clamp(sound.PlaybackLoudness / maxLoudness, 0, 1)
bar.Size = UDim2.new(amplitude, 0, 1, 0)
wait(0.05)
end

PlaybackRegion
Ler Parallel
Recursos: LegacySound
Sound.PlaybackRegion:NumberRange

PlaybackRegionsEnabled
Ler Parallel
Recursos: LegacySound
Sound.PlaybackRegionsEnabled:boolean

PlaybackSpeed
Não replicado
Ler Parallel
Recursos: LegacySound
Sound.PlaybackSpeed:number
Amostras de código
Velocidade de Reproduçăo do Som
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://9120386436"
sound.Looped = true
sound.Parent = workspace
sound:Play()
task.wait(10)
sound.PlaybackSpeed = 3 -- 3x mais rápido
task.wait(5)
sound.PlaybackSpeed = 0.5 -- 2x mais lento
task.wait(5)
sound.PlaybackSpeed = 1 -- padrão

Playing
Não replicado
Ler Parallel
Recursos: LegacySound
Sound.Playing:boolean
Amostras de código
Reproduzindo Som
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://9120386436"
sound.Looped = true
sound.Parent = workspace
print("reproduzindo som")
sound.Playing = true
task.wait(10)
print("parando som")
sound.Playing = false
task.wait(5)
sound.Playing = true
local timePosition = sound.TimePosition
print("retomado na posição de tempo: " .. tostring(timePosition)) -- c. 10 segundos

PlayOnRemove
Ler Parallel
Recursos: LegacySound
Sound.PlayOnRemove:boolean

RollOffMaxDistance
Ler Parallel
Recursos: LegacySound
Sound.RollOffMaxDistance:number

RollOffMinDistance
Ler Parallel
Recursos: LegacySound
Sound.RollOffMinDistance:number

RollOffMode
Ler Parallel
Recursos: LegacySound
Sound.RollOffMode:Enum.RollOffMode

SoundGroup
Ler Parallel
Recursos: LegacySound
Sound.SoundGroup:SoundGroup

SoundId
Ler Parallel
Recursos: LegacySound
Sound.SoundId:ContentId

TimeLength
Somente leitura
Não replicado
Ler Parallel
Recursos: LegacySound
Sound.TimeLength:number
Amostras de código
Tocar um Som por uma Duração Específica
local function playForDuration(sound, duration)
if not sound.IsLoaded then
sound.Loaded:wait()
end
local speed = sound.TimeLength / duration
sound.PlaybackSpeed = speed
sound:Play()
end
local sound = script.Parent
playForDuration(sound, 5)

TimePosition
Não replicado
Ler Parallel
Recursos: LegacySound
Sound.TimePosition:number
Amostras de código
Posição do Tempo do Som
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://9120386436"
sound.Parent = workspace
sound.TimePosition = 30
sound:Play()
task.wait(5)
sound.TimePosition = 100
task.wait(5)
sound.TimePosition = 0

Volume
Ler Parallel
Recursos: LegacySound
Sound.Volume:number

Métodos
Pause
Recursos: LegacySound
Sound:Pause():()
Devolução
()
Amostras de código
Funções de Som
-- criar um som
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://9120386436"
if not sound.IsLoaded then
sound.Loaded:Wait()
end
-- ouvir eventos
sound.Played:Connect(function(_soundId)
print("Evento Sound.Played")
end)
sound.Paused:Connect(function(_soundId)
print("Evento Sound.Paused")
end)
sound.Resumed:Connect(function(_soundId)
print("Evento Sound.Resumed")
end)
sound.Stopped:Connect(function(_soundId)
print("Evento Sound.Stopped")
end)
sound:Play()
print("tocar", sound.Playing, sound.TimePosition) -- tocar true 0
task.wait(10)
sound:Pause()
print("pausar", sound.Playing, sound.TimePosition) -- pausar false 10
task.wait(3)
sound:Resume()
print("tocar", sound.Playing, sound.TimePosition) -- tocar true 10
task.wait(3)
sound:Stop()
print("parar", sound.Playing, sound.TimePosition) -- parar false 0
task.wait(3)
sound:Play()
print("tocar", sound.Playing, sound.TimePosition) -- tocar true 0

pause
Obsoleto

Play
Recursos: LegacySound
Sound:Play():()
Devolução
()
Amostras de código
Funções de Som
-- criar um som
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://9120386436"
if not sound.IsLoaded then
sound.Loaded:Wait()
end
-- ouvir eventos
sound.Played:Connect(function(_soundId)
print("Evento Sound.Played")
end)
sound.Paused:Connect(function(_soundId)
print("Evento Sound.Paused")
end)
sound.Resumed:Connect(function(_soundId)
print("Evento Sound.Resumed")
end)
sound.Stopped:Connect(function(_soundId)
print("Evento Sound.Stopped")
end)
sound:Play()
print("tocar", sound.Playing, sound.TimePosition) -- tocar true 0
task.wait(10)
sound:Pause()
print("pausar", sound.Playing, sound.TimePosition) -- pausar false 10
task.wait(3)
sound:Resume()
print("tocar", sound.Playing, sound.TimePosition) -- tocar true 10
task.wait(3)
sound:Stop()
print("parar", sound.Playing, sound.TimePosition) -- parar false 0
task.wait(3)
sound:Play()
print("tocar", sound.Playing, sound.TimePosition) -- tocar true 0

play
Obsoleto

Resume
Recursos: LegacySound
Sound:Resume():()
Devolução
()
Amostras de código
Funções de Som
-- criar um som
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://9120386436"
if not sound.IsLoaded then
sound.Loaded:Wait()
end
-- ouvir eventos
sound.Played:Connect(function(_soundId)
print("Evento Sound.Played")
end)
sound.Paused:Connect(function(_soundId)
print("Evento Sound.Paused")
end)
sound.Resumed:Connect(function(_soundId)
print("Evento Sound.Resumed")
end)
sound.Stopped:Connect(function(_soundId)
print("Evento Sound.Stopped")
end)
sound:Play()
print("tocar", sound.Playing, sound.TimePosition) -- tocar true 0
task.wait(10)
sound:Pause()
print("pausar", sound.Playing, sound.TimePosition) -- pausar false 10
task.wait(3)
sound:Resume()
print("tocar", sound.Playing, sound.TimePosition) -- tocar true 10
task.wait(3)
sound:Stop()
print("parar", sound.Playing, sound.TimePosition) -- parar false 0
task.wait(3)
sound:Play()
print("tocar", sound.Playing, sound.TimePosition) -- tocar true 0

Stop
Recursos: LegacySound
Sound:Stop():()
Devolução
()
Amostras de código
Funções de Som
-- criar um som
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://9120386436"
if not sound.IsLoaded then
sound.Loaded:Wait()
end
-- ouvir eventos
sound.Played:Connect(function(_soundId)
print("Evento Sound.Played")
end)
sound.Paused:Connect(function(_soundId)
print("Evento Sound.Paused")
end)
sound.Resumed:Connect(function(_soundId)
print("Evento Sound.Resumed")
end)
sound.Stopped:Connect(function(_soundId)
print("Evento Sound.Stopped")
end)
sound:Play()
print("tocar", sound.Playing, sound.TimePosition) -- tocar true 0
task.wait(10)
sound:Pause()
print("pausar", sound.Playing, sound.TimePosition) -- pausar false 10
task.wait(3)
sound:Resume()
print("tocar", sound.Playing, sound.TimePosition) -- tocar true 10
task.wait(3)
sound:Stop()
print("parar", sound.Playing, sound.TimePosition) -- parar false 0
task.wait(3)
sound:Play()
print("tocar", sound.Playing, sound.TimePosition) -- tocar true 0

stop
Obsoleto

Eventos
DidLoop
Recursos: LegacySound
Sound.DidLoop(
soundId:string, numOfTimesLooped:number
Parâmetros
soundId:string
numOfTimesLooped:number
Amostras de código
Repetir um Número de Vezes
local function loopNTimes(sound, numberOfLoops)
if not sound.IsPlaying then
sound.Looped = true
local connection = nil
connection = sound.DidLoop:Connect(function(_soundId, numOfTimesLooped)
print(numOfTimesLooped)
if numOfTimesLooped >= numberOfLoops then
-- desconectar a conexão
connection:Disconnect()
-- parar o som
sound:Stop()
end
end)
sound:Play()
end
end
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://0"
loopNTimes(sound, 5)

Ended
Recursos: LegacySound
Sound.Ended(soundId:string):RBXScriptSignal
Parâmetros
soundId:string

Loaded
Recursos: LegacySound
Sound.Loaded(soundId:string):RBXScriptSignal
Parâmetros
soundId:string
Amostras de código
Carregar Som
local sound = script.Parent.Sound
if not sound.IsLoaded then
sound.Loaded:Wait()
end
print("O som foi carregado!")

Paused
Recursos: LegacySound
Sound.Paused(soundId:string):RBXScriptSignal
Parâmetros
soundId:string
Amostras de código
Funções de Som
-- criar um som
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://9120386436"
if not sound.IsLoaded then
sound.Loaded:Wait()
end
-- ouvir eventos
sound.Played:Connect(function(_soundId)
print("Evento Sound.Played")
end)
sound.Paused:Connect(function(_soundId)
print("Evento Sound.Paused")
end)
sound.Resumed:Connect(function(_soundId)
print("Evento Sound.Resumed")
end)
sound.Stopped:Connect(function(_soundId)
print("Evento Sound.Stopped")
end)
sound:Play()
print("tocar", sound.Playing, sound.TimePosition) -- tocar true 0
task.wait(10)
sound:Pause()
print("pausar", sound.Playing, sound.TimePosition) -- pausar false 10
task.wait(3)
sound:Resume()
print("tocar", sound.Playing, sound.TimePosition) -- tocar true 10
task.wait(3)
sound:Stop()
print("parar", sound.Playing, sound.TimePosition) -- parar false 0
task.wait(3)
sound:Play()
print("tocar", sound.Playing, sound.TimePosition) -- tocar true 0

Played
Recursos: LegacySound
Sound.Played(soundId:string):RBXScriptSignal
Parâmetros
soundId:string
Amostras de código
Funções de Som
-- criar um som
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://9120386436"
if not sound.IsLoaded then
sound.Loaded:Wait()
end
-- ouvir eventos
sound.Played:Connect(function(_soundId)
print("Evento Sound.Played")
end)
sound.Paused:Connect(function(_soundId)
print("Evento Sound.Paused")
end)
sound.Resumed:Connect(function(_soundId)
print("Evento Sound.Resumed")
end)
sound.Stopped:Connect(function(_soundId)
print("Evento Sound.Stopped")
end)
sound:Play()
print("tocar", sound.Playing, sound.TimePosition) -- tocar true 0
task.wait(10)
sound:Pause()
print("pausar", sound.Playing, sound.TimePosition) -- pausar false 10
task.wait(3)
sound:Resume()
print("tocar", sound.Playing, sound.TimePosition) -- tocar true 10
task.wait(3)
sound:Stop()
print("parar", sound.Playing, sound.TimePosition) -- parar false 0
task.wait(3)
sound:Play()
print("tocar", sound.Playing, sound.TimePosition) -- tocar true 0

Resumed
Recursos: LegacySound
Sound.Resumed(soundId:string):RBXScriptSignal
Parâmetros
soundId:string
Amostras de código
Funções de Som
-- criar um som
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://9120386436"
if not sound.IsLoaded then
sound.Loaded:Wait()
end
-- ouvir eventos
sound.Played:Connect(function(_soundId)
print("Evento Sound.Played")
end)
sound.Paused:Connect(function(_soundId)
print("Evento Sound.Paused")
end)
sound.Resumed:Connect(function(_soundId)
print("Evento Sound.Resumed")
end)
sound.Stopped:Connect(function(_soundId)
print("Evento Sound.Stopped")
end)
sound:Play()
print("tocar", sound.Playing, sound.TimePosition) -- tocar true 0
task.wait(10)
sound:Pause()
print("pausar", sound.Playing, sound.TimePosition) -- pausar false 10
task.wait(3)
sound:Resume()
print("tocar", sound.Playing, sound.TimePosition) -- tocar true 10
task.wait(3)
sound:Stop()
print("parar", sound.Playing, sound.TimePosition) -- parar false 0
task.wait(3)
sound:Play()
print("tocar", sound.Playing, sound.TimePosition) -- tocar true 0

Stopped
Recursos: LegacySound
Sound.Stopped(soundId:string):RBXScriptSignal
Parâmetros
soundId:string
Amostras de código
Funções de Som
-- criar um som
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://9120386436"
if not sound.IsLoaded then
sound.Loaded:Wait()
end
-- ouvir eventos
sound.Played:Connect(function(_soundId)
print("Evento Sound.Played")
end)
sound.Paused:Connect(function(_soundId)
print("Evento Sound.Paused")
end)
sound.Resumed:Connect(function(_soundId)
print("Evento Sound.Resumed")
end)
sound.Stopped:Connect(function(_soundId)
print("Evento Sound.Stopped")
end)
sound:Play()
print("tocar", sound.Playing, sound.TimePosition) -- tocar true 0
task.wait(10)
sound:Pause()
print("pausar", sound.Playing, sound.TimePosition) -- pausar false 10
task.wait(3)
sound:Resume()
print("tocar", sound.Playing, sound.TimePosition) -- tocar true 10
task.wait(3)
sound:Stop()
print("parar", sound.Playing, sound.TimePosition) -- parar false 0
task.wait(3)
sound:Play()
print("tocar", sound.Playing, sound.TimePosition) -- tocar true 0

©2026 Roblox Corporation, Roblox, o logotipo Roblox e Powering Imagination estão entre nossas marcas registradas e não registradas nos EUA e em outros países.