Sound

Mostrar obsoleto

*Este contenido se traduce usando la IA (Beta) y puede contener errores. Para ver esta página en inglés, haz clic en aquí.

Sound es un objeto que emite sonido.Cuando se coloca en un BasePart o un Attachment , este objeto emitirá su sonido desde la parte de BasePart.Position o el conexiónde Attachment.WorldPosition .En esta colocación, un Sound exhibe el efecto Doppler, lo que significa que su frecuencia y tono varía con la movimiento relativo de cualquier accesorio o parte a la que está conectado.Además, su volumen se determinará por la distancia entre el reproductor de sonido del cliente (por defecto la posición Camera ) y la posición del padre del sonido.Para obtener más información, consulte RollOffMode .

Un sonido se considera "global" si no es padre de un BasePart o un Attachment .En este caso, el sonido se reproducirá al mismo volumen en todo el lugar.

Muestras de código

The code in this sample demonstrates how a sound parented to a Part or Attachment will play locally and experience volume drop off the further the player's camera is away from the part.

A part is instanced, and a sound is instanced and parented to the part. A click detector is set up on the part that will check if the sound is playing, using Sound.IsPlaying and play or stop the sound depending.

Music Playing Part

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
-- create a sound
local sound = Instance.new("Sound", part)
sound.SoundId = "rbxassetid://9120386436"
sound.EmitterSize = 5 -- decrease the emitter size (for earlier volume drop off)
sound.Looped = true
sound.Parent = part
local clickDetector = Instance.new("ClickDetector")
clickDetector.Parent = part
-- toggle the sound playing / not playing
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)

Resumen

Propiedades

Métodos

Eventos

Propiedades

ChannelCount

Solo lectura
No replicado
No explorable
Seguridad de scripts Roblox
Leer paralelo

IsLoaded

Solo lectura
No replicado
Leer paralelo

Esta propiedad es true cuando el Sound se ha cargado de los servidores de Roblox y está listo para jugar.Puedes usar esta propiedad y el evento Loaded para verificar que un sonido se ha cargado antes de reproducirlo.

Muestras de código

This simple function will verify a Sound has loaded by checking the Sound.IsLoaded property. If Sound.IsLoaded is false it will wait for the Loaded event before resuming.

It is important to check Sound.IsLoaded before connecting to the Sound.Loaded event, as if the sound has already loaded the Sound.Loaded event will not fire and the function will yield indefinitely.

Load Sound

local sound = script.Parent.Sound
if not sound.IsLoaded then
sound.Loaded:Wait()
end
print("The sound has loaded!")

IsPaused

Oculto
Solo lectura
No replicado
Leer paralelo

Esta propiedad de solo lectura devuelve true cuando el Sound no está jugando.Tenga en cuenta que puede devolver true si un sonido se ha pausado usando Pause() , si se ha detenido usando Stop() o el sonido nunca se ha reproducido.

Como IsPaused es de lectura solo, no se puede usar para detener el sonido; Stop() o Pause() debería usarse en su lugar.

Muestras de código

This code sample contains demonstrates when the Sound.IsPlaying and Sound.IsPaused properties will be true or false.

A sound is instanced in the Workspace and the Sound.IsLoaded property is checked to ensure it has loaded, if it has not the Sound.Loaded event is used to yield the script until the sound has.

As the sound is played, paused and stopped the Sound.IsPlaying and Sound.IsPaused properties are printed to demonstrate how they respond to each of these functions. Note Sound.IsPaused will always be true if even if the sound has been stopped rather than paused.

Sound IsPlaying and SoundIsPaused

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) -- true, false
task.wait(2)
sound:Pause()
print(sound.IsPlaying, sound.IsPaused) -- false, true
task.wait(2)
sound:Play()
print(sound.IsPlaying, sound.IsPaused) -- true, false
task.wait(2)
sound:Stop()
print(sound.IsPlaying, sound.IsPaused) -- false, true

IsPlaying

Oculto
Solo lectura
No replicado
Leer paralelo

Esta propiedad de solo lectura devuelve verdad cuando el Sound está jugando.

Como IsPlaying es de lectura solo, no se puede usar para reproducir el sonido; Play() debe usarse en su lugar.

Muestras de código

This code sample contains demonstrates when the Sound.IsPlaying and Sound.IsPaused properties will be true or false.

A sound is instanced in the Workspace and the Sound.IsLoaded property is checked to ensure it has loaded, if it has not the Sound.Loaded event is used to yield the script until the sound has.

As the sound is played, paused and stopped the Sound.IsPlaying and Sound.IsPaused properties are printed to demonstrate how they respond to each of these functions. Note Sound.IsPaused will always be true if even if the sound has been stopped rather than paused.

Sound IsPlaying and SoundIsPaused

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) -- true, false
task.wait(2)
sound:Pause()
print(sound.IsPlaying, sound.IsPaused) -- false, true
task.wait(2)
sound:Play()
print(sound.IsPlaying, sound.IsPaused) -- true, false
task.wait(2)
sound:Stop()
print(sound.IsPlaying, sound.IsPaused) -- false, true

LoopRegion

Leer paralelo

Un rango que denota un comienzo y final de bucle deseado dentro del PlaybackRegion, en segundos.

  • Si Class.Sound.LoopRegion|LoopRegion.Min``>``Class.Sound.PlaybackRegion|PlaybackRegion.Min , el bucle comienza desde LoopRegion.Min .

  • Si Class.Sound.LoopRegion|LoopRegion.Min``<``Class.Sound.PlaybackRegion|PlaybackRegion.Min , el bucle comienza desde PlaybackRegion.Min .

  • Si Class.Sound.LoopRegion|LoopRegion.Max``>``Class.Sound.PlaybackRegion|PlaybackRegion.Max , el bucle comienza en PlaybackRegion.Max .

  • Si Class.Sound.LoopRegion|LoopRegion.Max``<``Class.Sound.PlaybackRegion|PlaybackRegion.Max , el bucle comienza en exactamente ese momento.

  • Si Class.Sound.LoopRegion|LoopRegion.Min``==``Class.Sound.LoopRegion|LoopRegion.Max , el Sound usa la propiedad PlaybackRegion en su lugar.

Looped

Leer paralelo

Esto establece si o no la repetición Sound se repite una vez que haya terminado de jugar.Los sonidos en bucle son adecuados para una variedad de aplicaciones, incluidos la música y los sonidos ambientales de fondo.

El evento DidLoop se puede usar para rastrear el número de veces que el sonido se ha repetido.

Muestras de código

This code sample includes a function that will play a sound and allow it to loop for a given number of times before stopping it.

Loop a Number of Times

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
-- disconnect the connection
connection:Disconnect()
-- stop the sound
sound:Stop()
end
end)
sound:Play()
end
end
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://0"
loopNTimes(sound, 5)

PlayOnRemove

Leer paralelo

Cuando true , el Sound jugará cuando se elimine de la experiencia al padrear el Sound o uno si sus ancestros son a nil .Esto significa que todo lo siguiente causará que se reproduzca el sonido cuando PlayOnRemove sea true :

  • sound:Destroy()
  • sound.Parent = nil
  • sound.Parent.Parent = nil

PlaybackLoudness

Solo lectura
No replicado
Leer paralelo

Un número entre 0 y 1000 que indica cuán fuerte está reproducido actualmente el Sound.Esta propiedad refleja la amplitud de la reproducción del sonido en la instancia del tiempo en que se leído.

Muestras de código

In this sample Sound.PlaybackLoudness is used to create an amplitude bar that shows the amplitude of a sound playing.

This code sample should be placed in StarterPlayerScripts.

A simple GUI is created, a frame holding that bar and a frame containing the bar. A Sound is then played and the size of the bar is set to reflect the Sound.PlaybackLoudness on a loop.

Volume Amplitude Bar

-- to be placed in StarterPlayer > StarterPlayerScripts
local Players = game:GetService("Players")
-- wait for local player PlayerGui
local LocalPlayer = Players.LocalPlayer
local playerGui = LocalPlayer:WaitForChild("PlayerGui")
-- create a ScreenGui
local screenGui = Instance.new("ScreenGui")
screenGui.Parent = playerGui
-- create a holder for our bar
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
-- create a bar
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
-- create a sound
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://9120386436"
sound.Looped = true
sound.Parent = screenGui
sound:Play()
-- define a max loudness
local maxLoudness = 30
-- animate the amplitude bar
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

Leer paralelo

Un rango que denota un tiempo de inicio y de parada deseado dentro del TimeLength, en segundos.

PlaybackRegionsEnabled

Leer paralelo

Si true , esta propiedad le da a tu Sound acceso a las propiedades PlaybackRegion y LoopRegion que pueden controlar más precisamente su reproducción.

PlaybackSpeed

No replicado
Leer paralelo

Determina la velocidad a la que se jugarun Sound con valores más altos que hagan que el sonido se reproduzca más rápido y a un tono más alto.

Muestras de código

In this example a Sound is played in the Workspace. The PlaybackSpeed property is increased and decreased at intervals to demonstrate its impact on the playback of the Sound.

Sound PlaybackSpeed

local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://9120386436"
sound.Looped = true
sound.Parent = workspace
sound:Play()
task.wait(10)
sound.PlaybackSpeed = 3 -- 3x faster
task.wait(5)
sound.PlaybackSpeed = 0.5 -- 2x slower
task.wait(5)
sound.PlaybackSpeed = 1 -- default

Playing

No replicado
Leer paralelo

Indica si el Sound está jugando actualmente. Esto se puede alternar, y esta propiedad siempre se replicará.

En la ventana Propiedades de Studio, mientras estás en el modo Editar , al alternar Playing a true no comienza a reproducirse el sonido, pero el sonido comenzará a reproducirse durante tiempo de ejecuciónejecución.

Esta propiedad no debe confundirse con IsPlaying que es una propiedad de solo lectura.

Tenga en cuenta que cuando Playing se establece en false , la propiedad TimePosition de sonido no se restablecerá, lo que significa que cuando Playing se establece nuevamente en true , el audio continuará desde la posición de tiempo en la que se detuvo cuando se detuvo.Sin embargo, si se usa la función Play() para reanudar el sonido, la posición del tiempo se restablecerá a 0.

Muestras de código

This sample demonstrates how the Sound.Playing property can be used to start and stop playback of a sound.

A sound is instanced in the Workspace and playback is started by setting Sound.Playing to true. After ten seconds the playback is stopped by setting Sound.Playing to false. When the playback is again resumed using Sound.Playing it resumes at the previous Sound.TimePosition it was stopped at. This is demonstrated by printing the TimePosition property immediately after resuming the sound.

Sound Playing

local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://9120386436"
sound.Looped = true
sound.Parent = workspace
print("playing sound")
sound.Playing = true
task.wait(10)
print("stopping sound")
sound.Playing = false
task.wait(5)
sound.Playing = true
local timePosition = sound.TimePosition
print("resumed at time position: " .. tostring(timePosition)) -- c. 10 seconds

RollOffMaxDistance

Leer paralelo

La distancia máxima, en studs, el oyente de un cliente puede ser desde el origen del sonido y aún así escucharlo.Solo se aplica a Sounds padres a un BasePart o Attachment .

Cómo RollOffMaxDistance influye en la atenuación de un sonido (la manera en que se desvanece) depende de la propiedad RollOffMode.

RollOffMinDistance

Leer paralelo

La distancia mínima, en studs, a la cual un Sound que está parentizado a un BasePart o Attachment comenzará a atenuarse (disminución del volumen).

Cómo RollOffMinDistance influye en la atenuación de un sonido (la manera en que se desvanece) depende de la propiedad RollOffMode.

RollOffMode

Leer paralelo

Esta propiedad controla cómo el volumen de un Sound que está asociado a un BasePart o Attachment disminuye (desaparece) a medida que aumenta la distancia entre el receptor y el padre.

Para obtener detalles sobre los diferentes modos, consulte Enum.RollOffMode .

SoundGroup

Leer paralelo

El SoundGroup que está vinculado a este Sound .

SoundId

ContentId
Leer paralelo

Esta propiedad es el ID del contenido del archivo de sonido para asociar con el Sound . Ve Recursos de audio para obtener más información.

TimeLength

Solo lectura
No replicado
Leer paralelo

La longitud del Sound en segundos. Si el Sound no se carga, este valor será 0 .

Esta propiedad se usa a menudo en conjunción con PlaybackSpeed para ajustar la velocidad de un sonido para que dure durante una duración específica.

Muestras de código

This code sample includes a simple function that uses Sound.TimeLength and Sound.PlaybackSpeed to play a sound that'll take the given duration to complete. It achieves this by setting the PlaybackSpeed of the sound to be equal to the TimeLength of the sound divided by the desired duration.

Note that as TimeLength is equal to 0 when the sound has not loaded, the function will yield while it loads the sound.

Play a Sound for a Specific Duration

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

No replicado
Leer paralelo

Esta propiedad refleja el progreso de la Sound en segundos.Se puede cambiar para mover la posición de reproducción del sonido tanto antes como durante la reproducción.

Cuando se reproduce como Sound, TimePosition aumenta a una velocidad de PlaybackSpeed por segundo.Una vez que TimePosition alcance TimeLength, el sonido se detendrá a menos que sea Looped.

Tenga en cuenta que establecer TimePosition a un valor mayor que la longitud en una pista en bucle no hará que se envuelva.Si ese comportamiento es deseado, considere el siguiente fragmento de código:


local newPosition = 1.5
if newPosition >= sound.TimeLength then
newPosition = newPosition - sound.TimeLength
end
sound.TimePosition = newPosition

Muestras de código

This sample demonstrates how Sound.TimePosition can be used to jump to particular points in an audio file both before and during Sound playback.

A Sound is created in the Workspace and set to start at 30 seconds in. During playback, it jumps forwards to 100 seconds and then back to the start (0 seconds).

Sound TimePosition

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

Leer paralelo

El volumen del Sound . Se puede establecer entre 0 y 10 y se predetermina a 0.5 .

Tenga en cuenta que si el Sound es un miembro de un SoundGroup , su volumen de reproducción (pero no su propiedad Volume ) será influenciado por la propiedad del grupo SoundGroup.Volume.

Métodos

Pause

()

Este método pausa la reproducción del Sound si está reproduciendo, estableciendo Playing a false .A diferencia de Stop(), no restablece TimePosition , lo que significa que el sonido se puede reanudar usando Resume() .


Devuelve

()

Muestras de código

This sample gives a simple demonstration of what each of the Sound functions (Sound.Play, Sound.Stop, Sound.Pause and Sound.Resume) do to Sound.Playing and Sound.TimePosition.

Sound Functions

-- create a sound
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://9120386436"
if not sound.IsLoaded then
sound.Loaded:Wait()
end
-- listen for events
sound.Played:Connect(function(_soundId)
print("Sound.Played event")
end)
sound.Paused:Connect(function(_soundId)
print("Sound.Paused event")
end)
sound.Resumed:Connect(function(_soundId)
print("Sound.Resumed event")
end)
sound.Stopped:Connect(function(_soundId)
print("Sound.Stopped event")
end)
sound:Play()
print("play", sound.Playing, sound.TimePosition) -- play true 0
task.wait(10)
sound:Pause()
print("pause", sound.Playing, sound.TimePosition) -- pause false 10
task.wait(3)
sound:Resume()
print("play", sound.Playing, sound.TimePosition) -- play true 10
task.wait(3)
sound:Stop()
print("stop", sound.Playing, sound.TimePosition) -- stop false 0
task.wait(3)
sound:Play()
print("play", sound.Playing, sound.TimePosition) -- play true 0

Play

()

Este método juega el Sound y establece TimePosition al último valor establecido por un script (o 0 si no se ha establecer), luego establece Playing a true .


Devuelve

()

Muestras de código

This sample gives a simple demonstration of what each of the Sound functions (Sound.Play, Sound.Stop, Sound.Pause and Sound.Resume) do to Sound.Playing and Sound.TimePosition.

Sound Functions

-- create a sound
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://9120386436"
if not sound.IsLoaded then
sound.Loaded:Wait()
end
-- listen for events
sound.Played:Connect(function(_soundId)
print("Sound.Played event")
end)
sound.Paused:Connect(function(_soundId)
print("Sound.Paused event")
end)
sound.Resumed:Connect(function(_soundId)
print("Sound.Resumed event")
end)
sound.Stopped:Connect(function(_soundId)
print("Sound.Stopped event")
end)
sound:Play()
print("play", sound.Playing, sound.TimePosition) -- play true 0
task.wait(10)
sound:Pause()
print("pause", sound.Playing, sound.TimePosition) -- pause false 10
task.wait(3)
sound:Resume()
print("play", sound.Playing, sound.TimePosition) -- play true 10
task.wait(3)
sound:Stop()
print("stop", sound.Playing, sound.TimePosition) -- stop false 0
task.wait(3)
sound:Play()
print("play", sound.Playing, sound.TimePosition) -- play true 0

Resume

()

Este método resume el Sound y establece Playing a true .No altera TimePosition y por lo tanto se puede usar para reanudar la reproducción de un sonido pausado a través de Pause() .


Devuelve

()

Muestras de código

This sample gives a simple demonstration of what each of the Sound functions (Sound.Play, Sound.Stop, Sound.Pause and Sound.Resume) do to Sound.Playing and Sound.TimePosition.

Sound Functions

-- create a sound
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://9120386436"
if not sound.IsLoaded then
sound.Loaded:Wait()
end
-- listen for events
sound.Played:Connect(function(_soundId)
print("Sound.Played event")
end)
sound.Paused:Connect(function(_soundId)
print("Sound.Paused event")
end)
sound.Resumed:Connect(function(_soundId)
print("Sound.Resumed event")
end)
sound.Stopped:Connect(function(_soundId)
print("Sound.Stopped event")
end)
sound:Play()
print("play", sound.Playing, sound.TimePosition) -- play true 0
task.wait(10)
sound:Pause()
print("pause", sound.Playing, sound.TimePosition) -- pause false 10
task.wait(3)
sound:Resume()
print("play", sound.Playing, sound.TimePosition) -- play true 10
task.wait(3)
sound:Stop()
print("stop", sound.Playing, sound.TimePosition) -- stop false 0
task.wait(3)
sound:Play()
print("play", sound.Playing, sound.TimePosition) -- play true 0

Stop

()

Este método detiene el Sound y establece Playing a false , luego establece TimePosition a 0 .


Devuelve

()

Muestras de código

This sample gives a simple demonstration of what each of the Sound functions (Sound.Play, Sound.Stop, Sound.Pause and Sound.Resume) do to Sound.Playing and Sound.TimePosition.

Sound Functions

-- create a sound
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://9120386436"
if not sound.IsLoaded then
sound.Loaded:Wait()
end
-- listen for events
sound.Played:Connect(function(_soundId)
print("Sound.Played event")
end)
sound.Paused:Connect(function(_soundId)
print("Sound.Paused event")
end)
sound.Resumed:Connect(function(_soundId)
print("Sound.Resumed event")
end)
sound.Stopped:Connect(function(_soundId)
print("Sound.Stopped event")
end)
sound:Play()
print("play", sound.Playing, sound.TimePosition) -- play true 0
task.wait(10)
sound:Pause()
print("pause", sound.Playing, sound.TimePosition) -- pause false 10
task.wait(3)
sound:Resume()
print("play", sound.Playing, sound.TimePosition) -- play true 10
task.wait(3)
sound:Stop()
print("stop", sound.Playing, sound.TimePosition) -- stop false 0
task.wait(3)
sound:Play()
print("play", sound.Playing, sound.TimePosition) -- play true 0

Eventos

DidLoop

Se enciende cada vez que los bucles Sound se repiten.Devuelve soundId y numOfTimesLooped , dando el ID del contenido del sonido y el número de veces que se ha repetido respectivamente.

Cuando el Sound se detiene a través de Stop() , el contador en bucle se reinicia, lo que significa que el próximo evento DidLoop devolverá 1 para numOfTimesLooped .

Parámetros

soundId: string

El SoundId de la Sound que se repitió en bucle.

numOfTimesLooped: number

El número de veces que el Sound se ha repetido.


Muestras de código

This code sample includes a function that will play a sound and allow it to loop for a given number of times before stopping it.

Loop a Number of Times

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
-- disconnect the connection
connection:Disconnect()
-- stop the sound
sound:Stop()
end
end)
sound:Play()
end
end
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://0"
loopNTimes(sound, 5)

Ended

Se enciende cuando el Sound ha completado la reproducción y se ha detenido. Este evento se usa a menudo para destruir un sonido cuando se haya completado la reproducción:


sound:Play()
sound.Ended:Wait()
sound:Destroy()

Tenga en cuenta que este evento no disparará fuego por sonidos con Looped establecido en true , ya que continuarán tocando al llegar a su finalizar.Este evento también no disparará cuando el sonido se detenga antes de que se complete la reproducción; para esto use el evento Stopped.

Parámetros

soundId: string

El SoundId de los Sound que se ha terminado.


Loaded

Se enciende cuando se carga el Sound.

Como este evento solo se activa cuando se carga el sonido, se recomienda verificar la propiedad IsLoaded del sonido antes de conectarse a este evento.

Parámetros

soundId: string

El SoundId de los Sound que se cargaron.


Muestras de código

This simple function will verify a Sound has loaded by checking the Sound.IsLoaded property. If Sound.IsLoaded is false it will wait for the Loaded event before resuming.

It is important to check Sound.IsLoaded before connecting to the Sound.Loaded event, as if the sound has already loaded the Sound.Loaded event will not fire and the function will yield indefinitely.

Load Sound

local sound = script.Parent.Sound
if not sound.IsLoaded then
sound.Loaded:Wait()
end
print("The sound has loaded!")

Paused

Se enciende cada vez que el Sound se pausa usando Pause() .

Parámetros

soundId: string

El SoundId de los Sound que se pausaron.


Muestras de código

This sample gives a simple demonstration of what each of the Sound functions (Sound.Play, Sound.Stop, Sound.Pause and Sound.Resume) do to Sound.Playing and Sound.TimePosition.

Sound Functions

-- create a sound
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://9120386436"
if not sound.IsLoaded then
sound.Loaded:Wait()
end
-- listen for events
sound.Played:Connect(function(_soundId)
print("Sound.Played event")
end)
sound.Paused:Connect(function(_soundId)
print("Sound.Paused event")
end)
sound.Resumed:Connect(function(_soundId)
print("Sound.Resumed event")
end)
sound.Stopped:Connect(function(_soundId)
print("Sound.Stopped event")
end)
sound:Play()
print("play", sound.Playing, sound.TimePosition) -- play true 0
task.wait(10)
sound:Pause()
print("pause", sound.Playing, sound.TimePosition) -- pause false 10
task.wait(3)
sound:Resume()
print("play", sound.Playing, sound.TimePosition) -- play true 10
task.wait(3)
sound:Stop()
print("stop", sound.Playing, sound.TimePosition) -- stop false 0
task.wait(3)
sound:Play()
print("play", sound.Playing, sound.TimePosition) -- play true 0

Played

Se enciende cada vez que se reproduce el Sound usando Play() .Este evento no disparará si el Sound se reproduce debido a que se ha establecido PlayOnRemove en true y el sonido se ha destruido.

Parámetros

soundId: string

El SoundId de los Sound que se reprodujeron.


Muestras de código

This sample gives a simple demonstration of what each of the Sound functions (Sound.Play, Sound.Stop, Sound.Pause and Sound.Resume) do to Sound.Playing and Sound.TimePosition.

Sound Functions

-- create a sound
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://9120386436"
if not sound.IsLoaded then
sound.Loaded:Wait()
end
-- listen for events
sound.Played:Connect(function(_soundId)
print("Sound.Played event")
end)
sound.Paused:Connect(function(_soundId)
print("Sound.Paused event")
end)
sound.Resumed:Connect(function(_soundId)
print("Sound.Resumed event")
end)
sound.Stopped:Connect(function(_soundId)
print("Sound.Stopped event")
end)
sound:Play()
print("play", sound.Playing, sound.TimePosition) -- play true 0
task.wait(10)
sound:Pause()
print("pause", sound.Playing, sound.TimePosition) -- pause false 10
task.wait(3)
sound:Resume()
print("play", sound.Playing, sound.TimePosition) -- play true 10
task.wait(3)
sound:Stop()
print("stop", sound.Playing, sound.TimePosition) -- stop false 0
task.wait(3)
sound:Play()
print("play", sound.Playing, sound.TimePosition) -- play true 0

Resumed

Se incendia cuando el Sound se reanuda usando Resume() .

Parámetros

soundId: string

El SoundId de la Sound que se reanuda.


Muestras de código

This sample gives a simple demonstration of what each of the Sound functions (Sound.Play, Sound.Stop, Sound.Pause and Sound.Resume) do to Sound.Playing and Sound.TimePosition.

Sound Functions

-- create a sound
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://9120386436"
if not sound.IsLoaded then
sound.Loaded:Wait()
end
-- listen for events
sound.Played:Connect(function(_soundId)
print("Sound.Played event")
end)
sound.Paused:Connect(function(_soundId)
print("Sound.Paused event")
end)
sound.Resumed:Connect(function(_soundId)
print("Sound.Resumed event")
end)
sound.Stopped:Connect(function(_soundId)
print("Sound.Stopped event")
end)
sound:Play()
print("play", sound.Playing, sound.TimePosition) -- play true 0
task.wait(10)
sound:Pause()
print("pause", sound.Playing, sound.TimePosition) -- pause false 10
task.wait(3)
sound:Resume()
print("play", sound.Playing, sound.TimePosition) -- play true 10
task.wait(3)
sound:Stop()
print("stop", sound.Playing, sound.TimePosition) -- stop false 0
task.wait(3)
sound:Play()
print("play", sound.Playing, sound.TimePosition) -- play true 0

Stopped

Se enciende cuando el Sound se detiene al usar Stop() . Destruir un sonido mientras se reproduce no causará que este evento se desencadenar.

Parámetros

soundId: string

El SoundId de los Sound que se detuvo.


Muestras de código

This sample gives a simple demonstration of what each of the Sound functions (Sound.Play, Sound.Stop, Sound.Pause and Sound.Resume) do to Sound.Playing and Sound.TimePosition.

Sound Functions

-- create a sound
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://9120386436"
if not sound.IsLoaded then
sound.Loaded:Wait()
end
-- listen for events
sound.Played:Connect(function(_soundId)
print("Sound.Played event")
end)
sound.Paused:Connect(function(_soundId)
print("Sound.Paused event")
end)
sound.Resumed:Connect(function(_soundId)
print("Sound.Resumed event")
end)
sound.Stopped:Connect(function(_soundId)
print("Sound.Stopped event")
end)
sound:Play()
print("play", sound.Playing, sound.TimePosition) -- play true 0
task.wait(10)
sound:Pause()
print("pause", sound.Playing, sound.TimePosition) -- pause false 10
task.wait(3)
sound:Resume()
print("play", sound.Playing, sound.TimePosition) -- play true 10
task.wait(3)
sound:Stop()
print("stop", sound.Playing, sound.TimePosition) -- stop false 0
task.wait(3)
sound:Play()
print("play", sound.Playing, sound.TimePosition) -- play true 0