Pelajari
Kelas Engine
Sound

*Konten ini diterjemahkan menggunakan AI (Beta) dan mungkin mengandung kesalahan. Untuk melihat halaman ini dalam bahasa Inggris, klik di sini.


Contoh Kode
Bagian Musik yang Diputar
local part = Instance.new("Part")
part.Anchored = true
part.Position = Vector3.new(0, 3, 0)
part.BrickColor = BrickColor.new("Merah terang")
part.Name = "KotakMusik"
part.Parent = workspace
-- buat sebuah suara
local sound = Instance.new("Sound", part)
sound.SoundId = "rbxassetid://9120386436"
sound.EmitterSize = 5 -- kurangi ukuran emitter (untuk penurunan volume yang lebih awal)
sound.Looped = true
sound.Parent = part
local clickDetector = Instance.new("ClickDetector")
clickDetector.Parent = part
-- alihkan suara diputar / tidak diputar
clickDetector.MouseClick:Connect(function()
if not sound.IsPlaying then
part.BrickColor = BrickColor.new("Hijau terang")
sound:Play()
else
part.BrickColor = BrickColor.new("Merah terang")
sound:Stop()
end
end)

Referensi API
Properti
AcousticSimulationEnabled
Baca Paralel
Kemampuan: LegacySound
Sound.AcousticSimulationEnabled:boolean

AudioContent
Tersembunyi
Baca Paralel
Kemampuan: LegacySound
Sound.AudioContent:Content

EmitterSize
Tidak digunakan lagi

IsLoaded
Hanya Baca
Tidak Direplikasi
Baca Paralel
Kemampuan: LegacySound
Sound.IsLoaded:boolean
Contoh Kode
Muat Suara
local sound = script.Parent.Sound
if not sound.IsLoaded then
sound.Loaded:Wait()
end
print("Suara telah dimuat!")

IsPaused
Tersembunyi
Hanya Baca
Tidak Direplikasi
Baca Paralel
Kemampuan: LegacySound
Sound.IsPaused:boolean
Contoh Kode
Suara Sedang Dimainkan dan Suara Dijeda
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
Tersembunyi
Hanya Baca
Tidak Direplikasi
Baca Paralel
Kemampuan: LegacySound
Sound.IsPlaying:boolean
Contoh Kode
Suara Sedang Dimainkan dan Suara Dijeda
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
Tidak digunakan lagi

Looped
Baca Paralel
Kemampuan: LegacySound
Sound.Looped:boolean
Contoh Kode
Ulangi Sebuah Angka Beberapa Kali
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
-- putuskan koneksi
connection:Disconnect()
-- hentikan suara
sound:Stop()
end
end)
sound:Play()
end
end
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://0"
loopNTimes(sound, 5)

LoopRegion
Baca Paralel
Kemampuan: LegacySound
Sound.LoopRegion:NumberRange

MaxDistance
Tidak digunakan lagi

MinDistance
Tidak digunakan lagi

Pitch
Tidak digunakan lagi

PlaybackLoudness
Hanya Baca
Tidak Direplikasi
Baca Paralel
Kemampuan: LegacySound
Sound.PlaybackLoudness:number
Contoh Kode
Bantalan Amplitudo Suara
-- harus ditempatkan di StarterPlayer > StarterPlayerScripts
local Players = game:GetService("Players")
-- tunggu untuk PlayerGui lokal
local LocalPlayer = Players.LocalPlayer
local playerGui = LocalPlayer:WaitForChild("PlayerGui")
-- buat ScreenGui
local screenGui = Instance.new("ScreenGui")
screenGui.Parent = playerGui
-- buat penampung untuk bantalan kita
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
-- buat bantalan
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
-- buat suara
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://9120386436"
sound.Looped = true
sound.Parent = screenGui
sound:Play()
-- tentukan kekuatan maksimum
local maxLoudness = 30
-- animasikan bantalan amplitudo
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
Baca Paralel
Kemampuan: LegacySound
Sound.PlaybackRegion:NumberRange

PlaybackRegionsEnabled
Baca Paralel
Kemampuan: LegacySound
Sound.PlaybackRegionsEnabled:boolean

PlaybackSpeed
Tidak Direplikasi
Baca Paralel
Kemampuan: LegacySound
Sound.PlaybackSpeed:number
Contoh Kode
Kecepatan Pemutaran Suara
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://9120386436"
sound.Looped = true
sound.Parent = workspace
sound:Play()
task.wait(10)
sound.PlaybackSpeed = 3 -- 3x lebih cepat
task.wait(5)
sound.PlaybackSpeed = 0.5 -- 2x lebih lambat
task.wait(5)
sound.PlaybackSpeed = 1 -- default

Playing
Tidak Direplikasi
Baca Paralel
Kemampuan: LegacySound
Sound.Playing:boolean
Contoh Kode
Memainkan Suara
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://9120386436"
sound.Looped = true
sound.Parent = workspace
print("memutar suara")
sound.Playing = true
task.wait(10)
print("menghentikan suara")
sound.Playing = false
task.wait(5)
sound.Playing = true
local timePosition = sound.TimePosition
print("dilanjutkan pada posisi waktu: " .. tostring(timePosition)) -- c. 10 detik

PlayOnRemove
Baca Paralel
Kemampuan: LegacySound
Sound.PlayOnRemove:boolean

RollOffMaxDistance
Baca Paralel
Kemampuan: LegacySound
Sound.RollOffMaxDistance:number

RollOffMinDistance
Baca Paralel
Kemampuan: LegacySound
Sound.RollOffMinDistance:number

RollOffMode
Baca Paralel
Kemampuan: LegacySound
Sound.RollOffMode:Enum.RollOffMode

SoundGroup
Baca Paralel
Kemampuan: LegacySound
Sound.SoundGroup:SoundGroup

SoundId
Baca Paralel
Kemampuan: LegacySound
Sound.SoundId:ContentId

TimeLength
Hanya Baca
Tidak Direplikasi
Baca Paralel
Kemampuan: LegacySound
Sound.TimeLength:number
Contoh Kode
Mainkan Suara untuk Durasi Tertentu
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
Tidak Direplikasi
Baca Paralel
Kemampuan: LegacySound
Sound.TimePosition:number
Contoh Kode
Posisi Waktu Suara
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
Baca Paralel
Kemampuan: LegacySound
Sound.Volume:number

Metode
Pause
Kemampuan: LegacySound
Sound:Pause():()
Memberikan nilai
()
Contoh Kode
Fungsi Suara
-- buat suara
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://9120386436"
if not sound.IsLoaded then
sound.Loaded:Wait()
end
-- dengarkan peristiwa
sound.Played:Connect(function(_soundId)
print("Peristiwa Sound.Played")
end)
sound.Paused:Connect(function(_soundId)
print("Peristiwa Sound.Paused")
end)
sound.Resumed:Connect(function(_soundId)
print("Peristiwa Sound.Resumed")
end)
sound.Stopped:Connect(function(_soundId)
print("Peristiwa Sound.Stopped")
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

pause
Tidak digunakan lagi

Play
Kemampuan: LegacySound
Sound:Play():()
Memberikan nilai
()
Contoh Kode
Fungsi Suara
-- buat suara
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://9120386436"
if not sound.IsLoaded then
sound.Loaded:Wait()
end
-- dengarkan peristiwa
sound.Played:Connect(function(_soundId)
print("Peristiwa Sound.Played")
end)
sound.Paused:Connect(function(_soundId)
print("Peristiwa Sound.Paused")
end)
sound.Resumed:Connect(function(_soundId)
print("Peristiwa Sound.Resumed")
end)
sound.Stopped:Connect(function(_soundId)
print("Peristiwa Sound.Stopped")
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
Tidak digunakan lagi

Resume
Kemampuan: LegacySound
Sound:Resume():()
Memberikan nilai
()
Contoh Kode
Fungsi Suara
-- buat suara
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://9120386436"
if not sound.IsLoaded then
sound.Loaded:Wait()
end
-- dengarkan peristiwa
sound.Played:Connect(function(_soundId)
print("Peristiwa Sound.Played")
end)
sound.Paused:Connect(function(_soundId)
print("Peristiwa Sound.Paused")
end)
sound.Resumed:Connect(function(_soundId)
print("Peristiwa Sound.Resumed")
end)
sound.Stopped:Connect(function(_soundId)
print("Peristiwa Sound.Stopped")
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
Kemampuan: LegacySound
Sound:Stop():()
Memberikan nilai
()
Contoh Kode
Fungsi Suara
-- buat suara
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://9120386436"
if not sound.IsLoaded then
sound.Loaded:Wait()
end
-- dengarkan peristiwa
sound.Played:Connect(function(_soundId)
print("Peristiwa Sound.Played")
end)
sound.Paused:Connect(function(_soundId)
print("Peristiwa Sound.Paused")
end)
sound.Resumed:Connect(function(_soundId)
print("Peristiwa Sound.Resumed")
end)
sound.Stopped:Connect(function(_soundId)
print("Peristiwa Sound.Stopped")
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
Tidak digunakan lagi

Acara
DidLoop
Kemampuan: LegacySound
Sound.DidLoop(
soundId:string, numOfTimesLooped:number
Parameter
soundId:string
numOfTimesLooped:number
Contoh Kode
Ulangi Sebuah Angka Beberapa Kali
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
-- putuskan koneksi
connection:Disconnect()
-- hentikan suara
sound:Stop()
end
end)
sound:Play()
end
end
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://0"
loopNTimes(sound, 5)

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

Loaded
Kemampuan: LegacySound
Sound.Loaded(soundId:string):RBXScriptSignal
Parameter
soundId:string
Contoh Kode
Muat Suara
local sound = script.Parent.Sound
if not sound.IsLoaded then
sound.Loaded:Wait()
end
print("Suara telah dimuat!")

Paused
Kemampuan: LegacySound
Sound.Paused(soundId:string):RBXScriptSignal
Parameter
soundId:string
Contoh Kode
Fungsi Suara
-- buat suara
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://9120386436"
if not sound.IsLoaded then
sound.Loaded:Wait()
end
-- dengarkan peristiwa
sound.Played:Connect(function(_soundId)
print("Peristiwa Sound.Played")
end)
sound.Paused:Connect(function(_soundId)
print("Peristiwa Sound.Paused")
end)
sound.Resumed:Connect(function(_soundId)
print("Peristiwa Sound.Resumed")
end)
sound.Stopped:Connect(function(_soundId)
print("Peristiwa Sound.Stopped")
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
Kemampuan: LegacySound
Sound.Played(soundId:string):RBXScriptSignal
Parameter
soundId:string
Contoh Kode
Fungsi Suara
-- buat suara
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://9120386436"
if not sound.IsLoaded then
sound.Loaded:Wait()
end
-- dengarkan peristiwa
sound.Played:Connect(function(_soundId)
print("Peristiwa Sound.Played")
end)
sound.Paused:Connect(function(_soundId)
print("Peristiwa Sound.Paused")
end)
sound.Resumed:Connect(function(_soundId)
print("Peristiwa Sound.Resumed")
end)
sound.Stopped:Connect(function(_soundId)
print("Peristiwa Sound.Stopped")
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
Kemampuan: LegacySound
Sound.Resumed(soundId:string):RBXScriptSignal
Parameter
soundId:string
Contoh Kode
Fungsi Suara
-- buat suara
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://9120386436"
if not sound.IsLoaded then
sound.Loaded:Wait()
end
-- dengarkan peristiwa
sound.Played:Connect(function(_soundId)
print("Peristiwa Sound.Played")
end)
sound.Paused:Connect(function(_soundId)
print("Peristiwa Sound.Paused")
end)
sound.Resumed:Connect(function(_soundId)
print("Peristiwa Sound.Resumed")
end)
sound.Stopped:Connect(function(_soundId)
print("Peristiwa Sound.Stopped")
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
Kemampuan: LegacySound
Sound.Stopped(soundId:string):RBXScriptSignal
Parameter
soundId:string
Contoh Kode
Fungsi Suara
-- buat suara
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://9120386436"
if not sound.IsLoaded then
sound.Loaded:Wait()
end
-- dengarkan peristiwa
sound.Played:Connect(function(_soundId)
print("Peristiwa Sound.Played")
end)
sound.Paused:Connect(function(_soundId)
print("Peristiwa Sound.Paused")
end)
sound.Resumed:Connect(function(_soundId)
print("Peristiwa Sound.Resumed")
end)
sound.Stopped:Connect(function(_soundId)
print("Peristiwa Sound.Stopped")
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

©2026 Roblox Corporation. Roblox, logo Roblox, dan Powering Imagination termasuk dalam merek dagang kami yang terdaftar dan tidak terdaftar di AS dan negara lainnya.