Kita belajar dari nol: pilih template → buat objek → tambahkan musik latar → efek suara (SFX) → tombol kontrol.
Hasil Akhir
1) Musik Latar
2) Koin
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()
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)
-- 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()
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)
Siap lanjut ke Lesson 27: Particle Effects & Visual FX 😉