Apprendre
Classe de moteur
Sound

*Ce contenu est traduit en utilisant l'IA (Beta) et peut contenir des erreurs. Pour consulter cette page en anglais, clique ici.


Échantillons de code
Part de Lecture de Musique
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
-- créer un son
local sound = Instance.new("Sound", part)
sound.SoundId = "rbxassetid://9120386436"
sound.EmitterSize = 5 -- diminuer la taille de l'émetteur (pour une diminution de volume antérieure)
sound.Looped = true
sound.Parent = part
local clickDetector = Instance.new("ClickDetector")
clickDetector.Parent = part
-- basculer le son entre lecture / non lecture
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)

Référence API
Propriétés
AcousticSimulationEnabled
Lecture parallèle
Capacités : LegacySound
Sound.AcousticSimulationEnabled:boolean

AudioContent
Caché
Lecture parallèle
Capacités : LegacySound
Sound.AudioContent:Content

EmitterSize
Déprécié

IsLoaded
Lecture uniquement
Non répliqué
Lecture parallèle
Capacités : LegacySound
Sound.IsLoaded:boolean
Échantillons de code
Charger le son
local sound = script.Parent.Sound
if not sound.IsLoaded then
sound.Loaded:Wait()
end
print("Le son a été chargé !")

IsPaused
Caché
Lecture uniquement
Non répliqué
Lecture parallèle
Capacités : LegacySound
Sound.IsPaused:boolean
Échantillons de code
Son est en cours de lecture et Son est en pause
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) -- vrai, faux
task.wait(2)
sound:Pause()
print(sound.IsPlaying, sound.IsPaused) -- faux, vrai
task.wait(2)
sound:Play()
print(sound.IsPlaying, sound.IsPaused) -- vrai, faux
task.wait(2)
sound:Stop()
print(sound.IsPlaying, sound.IsPaused) -- faux, vrai

IsPlaying
Caché
Lecture uniquement
Non répliqué
Lecture parallèle
Capacités : LegacySound
Sound.IsPlaying:boolean
Échantillons de code
Son est en cours de lecture et Son est en pause
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) -- vrai, faux
task.wait(2)
sound:Pause()
print(sound.IsPlaying, sound.IsPaused) -- faux, vrai
task.wait(2)
sound:Play()
print(sound.IsPlaying, sound.IsPaused) -- vrai, faux
task.wait(2)
sound:Stop()
print(sound.IsPlaying, sound.IsPaused) -- faux, vrai

isPlaying
Déprécié

Looped
Lecture parallèle
Capacités : LegacySound
Sound.Looped:boolean
Échantillons de code
Boucler un nombre de fois
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
-- déconnecter la connexion
connection:Disconnect()
-- arrêter le son
sound:Stop()
end
end)
sound:Play()
end
end
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://0"
loopNTimes(sound, 5)

LoopRegion
Lecture parallèle
Capacités : LegacySound
Sound.LoopRegion:NumberRange

MaxDistance
Déprécié

MinDistance
Déprécié

Pitch
Déprécié

PlaybackLoudness
Lecture uniquement
Non répliqué
Lecture parallèle
Capacités : LegacySound
Sound.PlaybackLoudness:number
Échantillons de code
Barre d'Amplitude de Volume
-- à placer dans StarterPlayer > StarterPlayerScripts
local Players = game:GetService("Players")
-- attendre le PlayerGui du joueur local
local LocalPlayer = Players.LocalPlayer
local playerGui = LocalPlayer:WaitForChild("PlayerGui")
-- créer un ScreenGui
local screenGui = Instance.new("ScreenGui")
screenGui.Parent = playerGui
-- créer un conteneur pour notre barre
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
-- créer une barre
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
-- créer un son
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://9120386436"
sound.Looped = true
sound.Parent = screenGui
sound:Play()
-- définir une amplitude maximale
local maxLoudness = 30
-- animer la barre d'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
Lecture parallèle
Capacités : LegacySound
Sound.PlaybackRegion:NumberRange

PlaybackRegionsEnabled
Lecture parallèle
Capacités : LegacySound
Sound.PlaybackRegionsEnabled:boolean

PlaybackSpeed
Non répliqué
Lecture parallèle
Capacités : LegacySound
Sound.PlaybackSpeed:number
Échantillons de code
Vitesse de lecture du son
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://9120386436"
sound.Looped = true
sound.Parent = workspace
sound:Play()
task.wait(10)
sound.PlaybackSpeed = 3 -- 3x plus rapide
task.wait(5)
sound.PlaybackSpeed = 0.5 -- 2x plus lent
task.wait(5)
sound.PlaybackSpeed = 1 -- par défaut

Playing
Non répliqué
Lecture parallèle
Capacités : LegacySound
Sound.Playing:boolean
Échantillons de code
Lecture de son
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://9120386436"
sound.Looped = true
sound.Parent = workspace
print("lecture du son")
sound.Playing = true
task.wait(10)
print("arrêt du son")
sound.Playing = false
task.wait(5)
sound.Playing = true
local timePosition = sound.TimePosition
print("reprise à la position de temps : " .. tostring(timePosition)) -- env. 10 secondes

PlayOnRemove
Lecture parallèle
Capacités : LegacySound
Sound.PlayOnRemove:boolean

RollOffMaxDistance
Lecture parallèle
Capacités : LegacySound
Sound.RollOffMaxDistance:number

RollOffMinDistance
Lecture parallèle
Capacités : LegacySound
Sound.RollOffMinDistance:number

RollOffMode
Lecture parallèle
Capacités : LegacySound
Sound.RollOffMode:Enum.RollOffMode

SoundGroup
Lecture parallèle
Capacités : LegacySound
Sound.SoundGroup:SoundGroup

SoundId
Lecture parallèle
Capacités : LegacySound
Sound.SoundId:ContentId

TimeLength
Lecture uniquement
Non répliqué
Lecture parallèle
Capacités : LegacySound
Sound.TimeLength:number
Échantillons de code
Jouer un son pendant une durée spécifique
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
Non répliqué
Lecture parallèle
Capacités : LegacySound
Sound.TimePosition:number
Échantillons de code
Position de Temps du Son
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
Lecture parallèle
Capacités : LegacySound
Sound.Volume:number

Méthodes
Pause
Capacités : LegacySound
Sound:Pause():()
Retours
()
Échantillons de code
Fonctions Sonores
-- créer un son
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://9120386436"
if not sound.IsLoaded then
sound.Loaded:Wait()
end
-- écouter les événements
sound.Played:Connect(function(_soundId)
print("Événement Sound.Played")
end)
sound.Paused:Connect(function(_soundId)
print("Événement Sound.Paused")
end)
sound.Resumed:Connect(function(_soundId)
print("Événement Sound.Resumed")
end)
sound.Stopped:Connect(function(_soundId)
print("Événement Sound.Stopped")
end)
sound:Play()
print("jouer", sound.Playing, sound.TimePosition) -- jouer vrai 0
task.wait(10)
sound:Pause()
print("pause", sound.Playing, sound.TimePosition) -- pause faux 10
task.wait(3)
sound:Resume()
print("jouer", sound.Playing, sound.TimePosition) -- jouer vrai 10
task.wait(3)
sound:Stop()
print("arrêter", sound.Playing, sound.TimePosition) -- arrêter faux 0
task.wait(3)
sound:Play()
print("jouer", sound.Playing, sound.TimePosition) -- jouer vrai 0

pause
Déprécié

Play
Capacités : LegacySound
Sound:Play():()
Retours
()
Échantillons de code
Fonctions Sonores
-- créer un son
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://9120386436"
if not sound.IsLoaded then
sound.Loaded:Wait()
end
-- écouter les événements
sound.Played:Connect(function(_soundId)
print("Événement Sound.Played")
end)
sound.Paused:Connect(function(_soundId)
print("Événement Sound.Paused")
end)
sound.Resumed:Connect(function(_soundId)
print("Événement Sound.Resumed")
end)
sound.Stopped:Connect(function(_soundId)
print("Événement Sound.Stopped")
end)
sound:Play()
print("jouer", sound.Playing, sound.TimePosition) -- jouer vrai 0
task.wait(10)
sound:Pause()
print("pause", sound.Playing, sound.TimePosition) -- pause faux 10
task.wait(3)
sound:Resume()
print("jouer", sound.Playing, sound.TimePosition) -- jouer vrai 10
task.wait(3)
sound:Stop()
print("arrêter", sound.Playing, sound.TimePosition) -- arrêter faux 0
task.wait(3)
sound:Play()
print("jouer", sound.Playing, sound.TimePosition) -- jouer vrai 0

play
Déprécié

Resume
Capacités : LegacySound
Sound:Resume():()
Retours
()
Échantillons de code
Fonctions Sonores
-- créer un son
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://9120386436"
if not sound.IsLoaded then
sound.Loaded:Wait()
end
-- écouter les événements
sound.Played:Connect(function(_soundId)
print("Événement Sound.Played")
end)
sound.Paused:Connect(function(_soundId)
print("Événement Sound.Paused")
end)
sound.Resumed:Connect(function(_soundId)
print("Événement Sound.Resumed")
end)
sound.Stopped:Connect(function(_soundId)
print("Événement Sound.Stopped")
end)
sound:Play()
print("jouer", sound.Playing, sound.TimePosition) -- jouer vrai 0
task.wait(10)
sound:Pause()
print("pause", sound.Playing, sound.TimePosition) -- pause faux 10
task.wait(3)
sound:Resume()
print("jouer", sound.Playing, sound.TimePosition) -- jouer vrai 10
task.wait(3)
sound:Stop()
print("arrêter", sound.Playing, sound.TimePosition) -- arrêter faux 0
task.wait(3)
sound:Play()
print("jouer", sound.Playing, sound.TimePosition) -- jouer vrai 0

Stop
Capacités : LegacySound
Sound:Stop():()
Retours
()
Échantillons de code
Fonctions Sonores
-- créer un son
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://9120386436"
if not sound.IsLoaded then
sound.Loaded:Wait()
end
-- écouter les événements
sound.Played:Connect(function(_soundId)
print("Événement Sound.Played")
end)
sound.Paused:Connect(function(_soundId)
print("Événement Sound.Paused")
end)
sound.Resumed:Connect(function(_soundId)
print("Événement Sound.Resumed")
end)
sound.Stopped:Connect(function(_soundId)
print("Événement Sound.Stopped")
end)
sound:Play()
print("jouer", sound.Playing, sound.TimePosition) -- jouer vrai 0
task.wait(10)
sound:Pause()
print("pause", sound.Playing, sound.TimePosition) -- pause faux 10
task.wait(3)
sound:Resume()
print("jouer", sound.Playing, sound.TimePosition) -- jouer vrai 10
task.wait(3)
sound:Stop()
print("arrêter", sound.Playing, sound.TimePosition) -- arrêter faux 0
task.wait(3)
sound:Play()
print("jouer", sound.Playing, sound.TimePosition) -- jouer vrai 0

stop
Déprécié

Événements
DidLoop
Capacités : LegacySound
Sound.DidLoop(
soundId:string, numOfTimesLooped:number
Paramètres
soundId:string
numOfTimesLooped:number
Échantillons de code
Boucler un nombre de fois
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
-- déconnecter la connexion
connection:Disconnect()
-- arrêter le son
sound:Stop()
end
end)
sound:Play()
end
end
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://0"
loopNTimes(sound, 5)

Ended
Capacités : LegacySound
Sound.Ended(soundId:string):RBXScriptSignal
Paramètres
soundId:string

Loaded
Capacités : LegacySound
Sound.Loaded(soundId:string):RBXScriptSignal
Paramètres
soundId:string
Échantillons de code
Charger le son
local sound = script.Parent.Sound
if not sound.IsLoaded then
sound.Loaded:Wait()
end
print("Le son a été chargé !")

Paused
Capacités : LegacySound
Sound.Paused(soundId:string):RBXScriptSignal
Paramètres
soundId:string
Échantillons de code
Fonctions Sonores
-- créer un son
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://9120386436"
if not sound.IsLoaded then
sound.Loaded:Wait()
end
-- écouter les événements
sound.Played:Connect(function(_soundId)
print("Événement Sound.Played")
end)
sound.Paused:Connect(function(_soundId)
print("Événement Sound.Paused")
end)
sound.Resumed:Connect(function(_soundId)
print("Événement Sound.Resumed")
end)
sound.Stopped:Connect(function(_soundId)
print("Événement Sound.Stopped")
end)
sound:Play()
print("jouer", sound.Playing, sound.TimePosition) -- jouer vrai 0
task.wait(10)
sound:Pause()
print("pause", sound.Playing, sound.TimePosition) -- pause faux 10
task.wait(3)
sound:Resume()
print("jouer", sound.Playing, sound.TimePosition) -- jouer vrai 10
task.wait(3)
sound:Stop()
print("arrêter", sound.Playing, sound.TimePosition) -- arrêter faux 0
task.wait(3)
sound:Play()
print("jouer", sound.Playing, sound.TimePosition) -- jouer vrai 0

Played
Capacités : LegacySound
Sound.Played(soundId:string):RBXScriptSignal
Paramètres
soundId:string
Échantillons de code
Fonctions Sonores
-- créer un son
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://9120386436"
if not sound.IsLoaded then
sound.Loaded:Wait()
end
-- écouter les événements
sound.Played:Connect(function(_soundId)
print("Événement Sound.Played")
end)
sound.Paused:Connect(function(_soundId)
print("Événement Sound.Paused")
end)
sound.Resumed:Connect(function(_soundId)
print("Événement Sound.Resumed")
end)
sound.Stopped:Connect(function(_soundId)
print("Événement Sound.Stopped")
end)
sound:Play()
print("jouer", sound.Playing, sound.TimePosition) -- jouer vrai 0
task.wait(10)
sound:Pause()
print("pause", sound.Playing, sound.TimePosition) -- pause faux 10
task.wait(3)
sound:Resume()
print("jouer", sound.Playing, sound.TimePosition) -- jouer vrai 10
task.wait(3)
sound:Stop()
print("arrêter", sound.Playing, sound.TimePosition) -- arrêter faux 0
task.wait(3)
sound:Play()
print("jouer", sound.Playing, sound.TimePosition) -- jouer vrai 0

Resumed
Capacités : LegacySound
Sound.Resumed(soundId:string):RBXScriptSignal
Paramètres
soundId:string
Échantillons de code
Fonctions Sonores
-- créer un son
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://9120386436"
if not sound.IsLoaded then
sound.Loaded:Wait()
end
-- écouter les événements
sound.Played:Connect(function(_soundId)
print("Événement Sound.Played")
end)
sound.Paused:Connect(function(_soundId)
print("Événement Sound.Paused")
end)
sound.Resumed:Connect(function(_soundId)
print("Événement Sound.Resumed")
end)
sound.Stopped:Connect(function(_soundId)
print("Événement Sound.Stopped")
end)
sound:Play()
print("jouer", sound.Playing, sound.TimePosition) -- jouer vrai 0
task.wait(10)
sound:Pause()
print("pause", sound.Playing, sound.TimePosition) -- pause faux 10
task.wait(3)
sound:Resume()
print("jouer", sound.Playing, sound.TimePosition) -- jouer vrai 10
task.wait(3)
sound:Stop()
print("arrêter", sound.Playing, sound.TimePosition) -- arrêter faux 0
task.wait(3)
sound:Play()
print("jouer", sound.Playing, sound.TimePosition) -- jouer vrai 0

Stopped
Capacités : LegacySound
Sound.Stopped(soundId:string):RBXScriptSignal
Paramètres
soundId:string
Échantillons de code
Fonctions Sonores
-- créer un son
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://9120386436"
if not sound.IsLoaded then
sound.Loaded:Wait()
end
-- écouter les événements
sound.Played:Connect(function(_soundId)
print("Événement Sound.Played")
end)
sound.Paused:Connect(function(_soundId)
print("Événement Sound.Paused")
end)
sound.Resumed:Connect(function(_soundId)
print("Événement Sound.Resumed")
end)
sound.Stopped:Connect(function(_soundId)
print("Événement Sound.Stopped")
end)
sound:Play()
print("jouer", sound.Playing, sound.TimePosition) -- jouer vrai 0
task.wait(10)
sound:Pause()
print("pause", sound.Playing, sound.TimePosition) -- pause faux 10
task.wait(3)
sound:Resume()
print("jouer", sound.Playing, sound.TimePosition) -- jouer vrai 10
task.wait(3)
sound:Stop()
print("arrêter", sound.Playing, sound.TimePosition) -- arrêter faux 0
task.wait(3)
sound:Play()
print("jouer", sound.Playing, sound.TimePosition) -- jouer vrai 0

©2026 Société Roblox. Roblox, le logo Roblox et Powering Imagination font partie de nos marques déposées aux États-Unis et dans d'autres pays.