NEBULA • Roblox (9–12) Lesson 26 · Musik & Sound Effect
Slide 1/10
Lesson 26

Musik & Sound Effect (Step-by-Step)

Kita belajar dari nol: pilih template → buat objek → tambahkan musik latar → efek suara (SFX) → tombol kontrol.

Hasil Akhir

  • Musik latar otomatis play
  • Koin berbunyi saat disentuh
  • Tombol GUI untuk Play/Pause

Langkah 1 — Pilih Template

  1. Buka Roblox Studio
  2. Pilih Baseplate sebagai template
  3. Save project: File → Save As

Langkah 2 — Buat Objek

1) Musik Latar

  • Buka Explorer → klik kanan SoundServiceInsert ObjectSound
  • Rename: BGM
  • Set Looped = true, Volume = 0.3–0.5

2) Koin

  • WorkspacePart (Sphere)
  • Warna kuning, Material Metal/Neon
  • Rename: Coin, Anchored = true

Langkah 3 — Atur Musik Latar

Isi SoundId di SoundService/BGM dengan ID audio dari Toolbox (contoh: rbxassetid://1843520911).

-- ServerScriptService/BGMStarter.lua
local ss = game:GetService("SoundService")
local bgm = ss:WaitForChild("BGM")
bgm.Looped = true
bgm.Volume = 0.4
bgm:Play()

Langkah 4 — Efek Suara pada Koin

Tambahkan Sound sebagai child dari Coin dan isi SoundId SFX (misal: rbxassetid://12222142).

-- Workspace/Coin/Script
local coin = script.Parent
local sfx = coin:WaitForChild("Sound")
coin.Touched:Connect(function(hit)
  local hum = hit.Parent:FindFirstChild("Humanoid")
  if hum then
    sfx:Play()
    coin.Transparency = 1
    coin.CanCollide = false
    task.wait(0.4)
    coin:Destroy()
  end
end)

Langkah 5 — Tombol Play/Pause

  1. StarterGuiScreenGuiTextButton (Text = "Pause BGM")
  2. Di TextButton tambahkan LocalScript:
-- StarterGui/ScreenGui/TextButton/LocalScript
local btn = script.Parent
local bgm = game.SoundService:WaitForChild("BGM")
local paused = false

local function update()
  btn.Text = paused and "Play BGM" or "Pause BGM"
end

btn.MouseButton1Click:Connect(function()
  paused = not paused
  if paused then bgm:Pause() else bgm:Resume() end
  update()
end)

update()

Bonus: Volume Slider

Tambahkan TextBox (0–1). Saat diubah, set SoundService.BGM.Volume.

-- StarterGui/VolumeBox/LocalScript
local box = script.Parent
local bgm = game.SoundService:WaitForChild("BGM")
box.FocusLost:Connect(function(enter)
  if enter then
    local v = tonumber(box.Text) or 0.4
    v = math.clamp(v, 0, 1)
    bgm.Volume = v
  end
end)

Tips & Troubleshooting

  • Jika musik tidak terdengar: cek SoundId, Volume, dan Output error.
  • Gunakan Looped untuk BGM, PlayOnce untuk SFX.
  • BGM di SoundService → terdengar global, tidak ikut dipindah objek.

Quiz Cepat (3 Pertanyaan)

Q1. Di mana tempat terbaik menaruh musik latar supaya terdengar global?
Workspace dalam Part
SoundService sebagai parent Sound
StarterGui
Q2. Properti apa yang perlu diaktifkan agar musik diputar berulang-ulang?
Muted
Pitch
Looped
Q3. Kapan SFX koin diputar pada contoh di lesson ini?
Saat part koin disentuh pemain
Saat game dimulai
Saat tombol GUI ditekan

Penutup & Checklist

  • ✅ BGM terpasang di SoundService/BGM dan otomatis play
  • ✅ SFX koin berbunyi saat disentuh
  • ✅ Tombol GUI berfungsi untuk Play/Pause

Siap lanjut ke Lesson 27: Particle Effects & Visual FX 😉