Lernen
Engine-Klasse
Sound

*Dieser Inhalt wurde mit KI (Beta) übersetzt und kann Fehler enthalten. Um diese Seite auf Englisch zu sehen, klicke hier.


Code-Beispiele
Musik Spielender Teil
local part = Instance.new("Part")
part.Anchored = true
part.Position = Vector3.new(0, 3, 0)
part.BrickColor = BrickColor.new("Hellrot")
part.Name = "Musikbox"
part.Parent = workspace
-- ein Geräusch erstellen
local sound = Instance.new("Sound", part)
sound.SoundId = "rbxassetid://9120386436"
sound.EmitterSize = 5 -- verringere die Emittergröße (für frühere Lautstärkeabnahme)
sound.Looped = true
sound.Parent = part
local clickDetector = Instance.new("ClickDetector")
clickDetector.Parent = part
-- das Abspielen des Sounds ein- / ausschalten
clickDetector.MouseClick:Connect(function()
if not sound.IsPlaying then
part.BrickColor = BrickColor.new("Hellgrün")
sound:Play()
else
part.BrickColor = BrickColor.new("Hellrot")
sound:Stop()
end
end)

API-Referenz
Eigenschaften
AcousticSimulationEnabled
Parallel lesen
Funktionen: LegacySound
Sound.AcousticSimulationEnabled:boolean

AudioContent
Verborgen
Parallel lesen
Funktionen: LegacySound
Sound.AudioContent:Content

EmitterSize
Veraltet

IsLoaded
Schreibgeschützt
Nicht repliziert
Parallel lesen
Funktionen: LegacySound
Sound.IsLoaded:boolean
Code-Beispiele
Geräusch laden
local sound = script.Parent.Sound
if not sound.IsLoaded then
sound.Loaded:Wait()
end
print("Das Geräusch wurde geladen!")

IsPaused
Verborgen
Schreibgeschützt
Nicht repliziert
Parallel lesen
Funktionen: LegacySound
Sound.IsPaused:boolean
Code-Beispiele
Sound IsPlaying und 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) -- wahr, falsch
task.wait(2)
sound:Pause()
print(sound.IsPlaying, sound.IsPaused) -- falsch, wahr
task.wait(2)
sound:Play()
print(sound.IsPlaying, sound.IsPaused) -- wahr, falsch
task.wait(2)
sound:Stop()
print(sound.IsPlaying, sound.IsPaused) -- falsch, wahr

IsPlaying
Verborgen
Schreibgeschützt
Nicht repliziert
Parallel lesen
Funktionen: LegacySound
Sound.IsPlaying:boolean
Code-Beispiele
Sound IsPlaying und 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) -- wahr, falsch
task.wait(2)
sound:Pause()
print(sound.IsPlaying, sound.IsPaused) -- falsch, wahr
task.wait(2)
sound:Play()
print(sound.IsPlaying, sound.IsPaused) -- wahr, falsch
task.wait(2)
sound:Stop()
print(sound.IsPlaying, sound.IsPaused) -- falsch, wahr

isPlaying
Veraltet

Looped
Parallel lesen
Funktionen: LegacySound
Sound.Looped:boolean
Code-Beispiele
Zahl mehrmals wiederholen
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
-- die Verbindung trennen
connection:Disconnect()
-- den Sound stoppen
sound:Stop()
end
end)
sound:Play()
end
end
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://0"
loopNTimes(sound, 5)

LoopRegion
Parallel lesen
Funktionen: LegacySound
Sound.LoopRegion:NumberRange

MaxDistance
Veraltet

MinDistance
Veraltet

Pitch
Veraltet

PlaybackLoudness
Schreibgeschützt
Nicht repliziert
Parallel lesen
Funktionen: LegacySound
Sound.PlaybackLoudness:number
Code-Beispiele
Lautstärke Amplitudenanzeige
-- muss in StarterPlayer > StarterPlayerScripts platziert werden
local Players = game:GetService("Players")
-- auf den lokalen Spieler PlayerGui warten
local LocalPlayer = Players.LocalPlayer
local playerGui = LocalPlayer:WaitForChild("PlayerGui")
-- ein ScreenGui erstellen
local screenGui = Instance.new("ScreenGui")
screenGui.Parent = playerGui
-- einen Halter für unsere Anzeige erstellen
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
-- eine Anzeige erstellen
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
-- einen Ton erstellen
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://9120386436"
sound.Looped = true
sound.Parent = screenGui
sound:Play()
-- eine maximale Lautstärke definieren
local maxLoudness = 30
-- die Amplitudenanzeige animieren
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
Parallel lesen
Funktionen: LegacySound
Sound.PlaybackRegion:NumberRange

PlaybackRegionsEnabled
Parallel lesen
Funktionen: LegacySound
Sound.PlaybackRegionsEnabled:boolean

PlaybackSpeed
Nicht repliziert
Parallel lesen
Funktionen: LegacySound
Sound.PlaybackSpeed:number
Code-Beispiele
Sound Wiedergabegeschwindigkeit
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://9120386436"
sound.Looped = true
sound.Parent = workspace
sound:Play()
task.wait(10)
sound.PlaybackSpeed = 3 -- 3x schneller
task.wait(5)
sound.PlaybackSpeed = 0.5 -- 2x langsamer
task.wait(5)
sound.PlaybackSpeed = 1 -- Standard

Playing
Nicht repliziert
Parallel lesen
Funktionen: LegacySound
Sound.Playing:boolean
Code-Beispiele
Ton Wiedergabe
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://9120386436"
sound.Looped = true
sound.Parent = workspace
print("Spiele Sound")
sound.Playing = true
task.wait(10)
print("Stoppe Sound")
sound.Playing = false
task.wait(5)
sound.Playing = true
local timePosition = sound.TimePosition
print("Fortgesetzt an der Zeitposition: " .. tostring(timePosition)) -- ca. 10 Sekunden

PlayOnRemove
Parallel lesen
Funktionen: LegacySound
Sound.PlayOnRemove:boolean

RollOffMaxDistance
Parallel lesen
Funktionen: LegacySound
Sound.RollOffMaxDistance:number

RollOffMinDistance
Parallel lesen
Funktionen: LegacySound
Sound.RollOffMinDistance:number

RollOffMode
Parallel lesen
Funktionen: LegacySound
Sound.RollOffMode:Enum.RollOffMode

SoundGroup
Parallel lesen
Funktionen: LegacySound
Sound.SoundGroup:SoundGroup

SoundId
Parallel lesen
Funktionen: LegacySound
Sound.SoundId:ContentId

TimeLength
Schreibgeschützt
Nicht repliziert
Parallel lesen
Funktionen: LegacySound
Sound.TimeLength:number
Code-Beispiele
Spiele einen Sound für eine bestimmte Dauer
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
Nicht repliziert
Parallel lesen
Funktionen: LegacySound
Sound.TimePosition:number
Code-Beispiele
Sound Zeitposition
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
Parallel lesen
Funktionen: LegacySound
Sound.Volume:number

Methoden
Pause
Funktionen: LegacySound
Sound:Pause():()
Rückgaben
()
Code-Beispiele
Sound-Funktionen
-- Erstelle einen Sound
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://9120386436"
if not sound.IsLoaded then
sound.Loaded:Wait()
end
-- Höre auf Ereignisse
sound.Played:Connect(function(_soundId)
print("Sound.Played Ereignis")
end)
sound.Paused:Connect(function(_soundId)
print("Sound.Paused Ereignis")
end)
sound.Resumed:Connect(function(_soundId)
print("Sound.Resumed Ereignis")
end)
sound.Stopped:Connect(function(_soundId)
print("Sound.Stopped Ereignis")
end)
sound:Play()
print("spielen", sound.Playing, sound.TimePosition) -- spielen true 0
task.wait(10)
sound:Pause()
print("pausieren", sound.Playing, sound.TimePosition) -- pausieren false 10
task.wait(3)
sound:Resume()
print("spielen", sound.Playing, sound.TimePosition) -- spielen true 10
task.wait(3)
sound:Stop()
print("stoppen", sound.Playing, sound.TimePosition) -- stoppen false 0
task.wait(3)
sound:Play()
print("spielen", sound.Playing, sound.TimePosition) -- spielen true 0

pause
Veraltet

Play
Funktionen: LegacySound
Sound:Play():()
Rückgaben
()
Code-Beispiele
Sound-Funktionen
-- Erstelle einen Sound
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://9120386436"
if not sound.IsLoaded then
sound.Loaded:Wait()
end
-- Höre auf Ereignisse
sound.Played:Connect(function(_soundId)
print("Sound.Played Ereignis")
end)
sound.Paused:Connect(function(_soundId)
print("Sound.Paused Ereignis")
end)
sound.Resumed:Connect(function(_soundId)
print("Sound.Resumed Ereignis")
end)
sound.Stopped:Connect(function(_soundId)
print("Sound.Stopped Ereignis")
end)
sound:Play()
print("spielen", sound.Playing, sound.TimePosition) -- spielen true 0
task.wait(10)
sound:Pause()
print("pausieren", sound.Playing, sound.TimePosition) -- pausieren false 10
task.wait(3)
sound:Resume()
print("spielen", sound.Playing, sound.TimePosition) -- spielen true 10
task.wait(3)
sound:Stop()
print("stoppen", sound.Playing, sound.TimePosition) -- stoppen false 0
task.wait(3)
sound:Play()
print("spielen", sound.Playing, sound.TimePosition) -- spielen true 0

play
Veraltet

Resume
Funktionen: LegacySound
Sound:Resume():()
Rückgaben
()
Code-Beispiele
Sound-Funktionen
-- Erstelle einen Sound
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://9120386436"
if not sound.IsLoaded then
sound.Loaded:Wait()
end
-- Höre auf Ereignisse
sound.Played:Connect(function(_soundId)
print("Sound.Played Ereignis")
end)
sound.Paused:Connect(function(_soundId)
print("Sound.Paused Ereignis")
end)
sound.Resumed:Connect(function(_soundId)
print("Sound.Resumed Ereignis")
end)
sound.Stopped:Connect(function(_soundId)
print("Sound.Stopped Ereignis")
end)
sound:Play()
print("spielen", sound.Playing, sound.TimePosition) -- spielen true 0
task.wait(10)
sound:Pause()
print("pausieren", sound.Playing, sound.TimePosition) -- pausieren false 10
task.wait(3)
sound:Resume()
print("spielen", sound.Playing, sound.TimePosition) -- spielen true 10
task.wait(3)
sound:Stop()
print("stoppen", sound.Playing, sound.TimePosition) -- stoppen false 0
task.wait(3)
sound:Play()
print("spielen", sound.Playing, sound.TimePosition) -- spielen true 0

Stop
Funktionen: LegacySound
Sound:Stop():()
Rückgaben
()
Code-Beispiele
Sound-Funktionen
-- Erstelle einen Sound
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://9120386436"
if not sound.IsLoaded then
sound.Loaded:Wait()
end
-- Höre auf Ereignisse
sound.Played:Connect(function(_soundId)
print("Sound.Played Ereignis")
end)
sound.Paused:Connect(function(_soundId)
print("Sound.Paused Ereignis")
end)
sound.Resumed:Connect(function(_soundId)
print("Sound.Resumed Ereignis")
end)
sound.Stopped:Connect(function(_soundId)
print("Sound.Stopped Ereignis")
end)
sound:Play()
print("spielen", sound.Playing, sound.TimePosition) -- spielen true 0
task.wait(10)
sound:Pause()
print("pausieren", sound.Playing, sound.TimePosition) -- pausieren false 10
task.wait(3)
sound:Resume()
print("spielen", sound.Playing, sound.TimePosition) -- spielen true 10
task.wait(3)
sound:Stop()
print("stoppen", sound.Playing, sound.TimePosition) -- stoppen false 0
task.wait(3)
sound:Play()
print("spielen", sound.Playing, sound.TimePosition) -- spielen true 0

stop
Veraltet

Events
DidLoop
Funktionen: LegacySound
Sound.DidLoop(
soundId:string, numOfTimesLooped:number
Parameter
soundId:string
numOfTimesLooped:number
Code-Beispiele
Zahl mehrmals wiederholen
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
-- die Verbindung trennen
connection:Disconnect()
-- den Sound stoppen
sound:Stop()
end
end)
sound:Play()
end
end
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://0"
loopNTimes(sound, 5)

Ended
Funktionen: LegacySound
Sound.Ended(soundId:string):RBXScriptSignal
Parameter
soundId:string

Loaded
Funktionen: LegacySound
Sound.Loaded(soundId:string):RBXScriptSignal
Parameter
soundId:string
Code-Beispiele
Geräusch laden
local sound = script.Parent.Sound
if not sound.IsLoaded then
sound.Loaded:Wait()
end
print("Das Geräusch wurde geladen!")

Paused
Funktionen: LegacySound
Sound.Paused(soundId:string):RBXScriptSignal
Parameter
soundId:string
Code-Beispiele
Sound-Funktionen
-- Erstelle einen Sound
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://9120386436"
if not sound.IsLoaded then
sound.Loaded:Wait()
end
-- Höre auf Ereignisse
sound.Played:Connect(function(_soundId)
print("Sound.Played Ereignis")
end)
sound.Paused:Connect(function(_soundId)
print("Sound.Paused Ereignis")
end)
sound.Resumed:Connect(function(_soundId)
print("Sound.Resumed Ereignis")
end)
sound.Stopped:Connect(function(_soundId)
print("Sound.Stopped Ereignis")
end)
sound:Play()
print("spielen", sound.Playing, sound.TimePosition) -- spielen true 0
task.wait(10)
sound:Pause()
print("pausieren", sound.Playing, sound.TimePosition) -- pausieren false 10
task.wait(3)
sound:Resume()
print("spielen", sound.Playing, sound.TimePosition) -- spielen true 10
task.wait(3)
sound:Stop()
print("stoppen", sound.Playing, sound.TimePosition) -- stoppen false 0
task.wait(3)
sound:Play()
print("spielen", sound.Playing, sound.TimePosition) -- spielen true 0

Played
Funktionen: LegacySound
Sound.Played(soundId:string):RBXScriptSignal
Parameter
soundId:string
Code-Beispiele
Sound-Funktionen
-- Erstelle einen Sound
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://9120386436"
if not sound.IsLoaded then
sound.Loaded:Wait()
end
-- Höre auf Ereignisse
sound.Played:Connect(function(_soundId)
print("Sound.Played Ereignis")
end)
sound.Paused:Connect(function(_soundId)
print("Sound.Paused Ereignis")
end)
sound.Resumed:Connect(function(_soundId)
print("Sound.Resumed Ereignis")
end)
sound.Stopped:Connect(function(_soundId)
print("Sound.Stopped Ereignis")
end)
sound:Play()
print("spielen", sound.Playing, sound.TimePosition) -- spielen true 0
task.wait(10)
sound:Pause()
print("pausieren", sound.Playing, sound.TimePosition) -- pausieren false 10
task.wait(3)
sound:Resume()
print("spielen", sound.Playing, sound.TimePosition) -- spielen true 10
task.wait(3)
sound:Stop()
print("stoppen", sound.Playing, sound.TimePosition) -- stoppen false 0
task.wait(3)
sound:Play()
print("spielen", sound.Playing, sound.TimePosition) -- spielen true 0

Resumed
Funktionen: LegacySound
Sound.Resumed(soundId:string):RBXScriptSignal
Parameter
soundId:string
Code-Beispiele
Sound-Funktionen
-- Erstelle einen Sound
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://9120386436"
if not sound.IsLoaded then
sound.Loaded:Wait()
end
-- Höre auf Ereignisse
sound.Played:Connect(function(_soundId)
print("Sound.Played Ereignis")
end)
sound.Paused:Connect(function(_soundId)
print("Sound.Paused Ereignis")
end)
sound.Resumed:Connect(function(_soundId)
print("Sound.Resumed Ereignis")
end)
sound.Stopped:Connect(function(_soundId)
print("Sound.Stopped Ereignis")
end)
sound:Play()
print("spielen", sound.Playing, sound.TimePosition) -- spielen true 0
task.wait(10)
sound:Pause()
print("pausieren", sound.Playing, sound.TimePosition) -- pausieren false 10
task.wait(3)
sound:Resume()
print("spielen", sound.Playing, sound.TimePosition) -- spielen true 10
task.wait(3)
sound:Stop()
print("stoppen", sound.Playing, sound.TimePosition) -- stoppen false 0
task.wait(3)
sound:Play()
print("spielen", sound.Playing, sound.TimePosition) -- spielen true 0

Stopped
Funktionen: LegacySound
Sound.Stopped(soundId:string):RBXScriptSignal
Parameter
soundId:string
Code-Beispiele
Sound-Funktionen
-- Erstelle einen Sound
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://9120386436"
if not sound.IsLoaded then
sound.Loaded:Wait()
end
-- Höre auf Ereignisse
sound.Played:Connect(function(_soundId)
print("Sound.Played Ereignis")
end)
sound.Paused:Connect(function(_soundId)
print("Sound.Paused Ereignis")
end)
sound.Resumed:Connect(function(_soundId)
print("Sound.Resumed Ereignis")
end)
sound.Stopped:Connect(function(_soundId)
print("Sound.Stopped Ereignis")
end)
sound:Play()
print("spielen", sound.Playing, sound.TimePosition) -- spielen true 0
task.wait(10)
sound:Pause()
print("pausieren", sound.Playing, sound.TimePosition) -- pausieren false 10
task.wait(3)
sound:Resume()
print("spielen", sound.Playing, sound.TimePosition) -- spielen true 10
task.wait(3)
sound:Stop()
print("stoppen", sound.Playing, sound.TimePosition) -- stoppen false 0
task.wait(3)
sound:Play()
print("spielen", sound.Playing, sound.TimePosition) -- spielen true 0

©2026 Roblox Corporation. Roblox, das Roblox-Logo und "Powering Imagination" gehören zu unseren eingetragenen und nicht eingetragenen Markenzeichen in den USA und anderen Ländern.