学ぶ
エンジンクラス
Sound

*このコンテンツは、ベータ版のAI(人工知能)を使用して翻訳されており、エラーが含まれている可能性があります。このページを英語で表示するには、 こちら をクリックしてください。


コードサンプル
音楽再生パート
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
-- 音を作成する
local sound = Instance.new("Sound", part)
sound.SoundId = "rbxassetid://9120386436"
sound.EmitterSize = 5 -- エミッターサイズを減少させる(音量低下を早くするため)
sound.Looped = true
sound.Parent = part
local clickDetector = Instance.new("ClickDetector")
clickDetector.Parent = part
-- 音の再生 / 停止を切り替える
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)

APIリファレンス
プロパティ
AcousticSimulationEnabled
並列読み取り
機能: LegacySound
Sound.AcousticSimulationEnabled:boolean

AudioContent
非表示
並列読み取り
機能: LegacySound
Sound.AudioContent:Content

EmitterSize
非推奨

IsLoaded
読み取り専用
複製されていません
並列読み取り
機能: LegacySound
Sound.IsLoaded:boolean
コードサンプル
サウンドを読み込む
local sound = script.Parent.Sound
if not sound.IsLoaded then
sound.Loaded:Wait()
end
print("サウンドが読み込まれました!")

IsPaused
非表示
読み取り専用
複製されていません
並列読み取り
機能: LegacySound
Sound.IsPaused:boolean
コードサンプル
サウンドが再生中とサウンドが一時停止中
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
非表示
読み取り専用
複製されていません
並列読み取り
機能: LegacySound
Sound.IsPlaying:boolean
コードサンプル
サウンドが再生中とサウンドが一時停止中
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
非推奨

Looped
並列読み取り
機能: LegacySound
Sound.Looped:boolean
コードサンプル
指定した回数だけループする
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
-- 接続を切断します
connection:Disconnect()
-- 音を停止します
sound:Stop()
end
end)
sound:Play()
end
end
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://0"
loopNTimes(sound, 5)

LoopRegion
並列読み取り
機能: LegacySound
Sound.LoopRegion:NumberRange

MaxDistance
非推奨

MinDistance
非推奨

Pitch
非推奨

PlaybackLoudness
読み取り専用
複製されていません
並列読み取り
機能: LegacySound
Sound.PlaybackLoudness:number
コードサンプル
ボリューム振幅バー
-- StarterPlayer > StarterPlayerScripts に配置すること
local Players = game:GetService("Players")
-- ローカルプレイヤーのPlayerGuiを待つ
local LocalPlayer = Players.LocalPlayer
local playerGui = LocalPlayer:WaitForChild("PlayerGui")
-- ScreenGuiを作成
local screenGui = Instance.new("ScreenGui")
screenGui.Parent = playerGui
-- バーのホルダーを作成
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
-- バーを作成
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
-- サウンドを作成
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://9120386436"
sound.Looped = true
sound.Parent = screenGui
sound:Play()
-- 最大音量を定義
local maxLoudness = 30
-- 振幅バーをアニメート
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
並列読み取り
機能: LegacySound
Sound.PlaybackRegion:NumberRange

PlaybackRegionsEnabled
並列読み取り
機能: LegacySound
Sound.PlaybackRegionsEnabled:boolean

PlaybackSpeed
複製されていません
並列読み取り
機能: LegacySound
Sound.PlaybackSpeed:number
コードサンプル
サウンド 再生速度
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://9120386436"
sound.Looped = true
sound.Parent = workspace
sound:Play()
task.wait(10)
sound.PlaybackSpeed = 3 -- 3倍速
task.wait(5)
sound.PlaybackSpeed = 0.5 -- 2倍遅い
task.wait(5)
sound.PlaybackSpeed = 1 -- デフォルト

Playing
複製されていません
並列読み取り
機能: LegacySound
Sound.Playing:boolean
コードサンプル
サウンド再生
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://9120386436"
sound.Looped = true
sound.Parent = workspace
print("サウンド再生中")
sound.Playing = true
task.wait(10)
print("サウンド停止中")
sound.Playing = false
task.wait(5)
sound.Playing = true
local timePosition = sound.TimePosition
print("再開時の時間位置: " .. tostring(timePosition)) -- 約 10 秒

PlayOnRemove
並列読み取り
機能: LegacySound
Sound.PlayOnRemove:boolean

RollOffMaxDistance
並列読み取り
機能: LegacySound
Sound.RollOffMaxDistance:number

RollOffMinDistance
並列読み取り
機能: LegacySound
Sound.RollOffMinDistance:number

RollOffMode
並列読み取り
機能: LegacySound
Sound.RollOffMode:Enum.RollOffMode

SoundGroup
並列読み取り
機能: LegacySound
Sound.SoundGroup:SoundGroup

SoundId
並列読み取り
機能: LegacySound
Sound.SoundId:ContentId

TimeLength
読み取り専用
複製されていません
並列読み取り
機能: LegacySound
Sound.TimeLength:number
コードサンプル
特定の期間サウンドを再生する
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
複製されていません
並列読み取り
機能: LegacySound
Sound.TimePosition:number
コードサンプル
サウンド時間位置
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
並列読み取り
機能: LegacySound
Sound.Volume:number

方法
Pause
機能: LegacySound
Sound:Pause():()
戻り値
()
コードサンプル
サウンド関数
-- サウンドを作成する
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://9120386436"
if not sound.IsLoaded then
sound.Loaded:Wait()
end
-- イベントをリッスンする
sound.Played:Connect(function(_soundId)
print("Sound.Played イベント")
end)
sound.Paused:Connect(function(_soundId)
print("Sound.Paused イベント")
end)
sound.Resumed:Connect(function(_soundId)
print("Sound.Resumed イベント")
end)
sound.Stopped:Connect(function(_soundId)
print("Sound.Stopped イベント")
end)
sound:Play()
print("再生", sound.Playing, sound.TimePosition) -- 再生 true 0
task.wait(10)
sound:Pause()
print("一時停止", sound.Playing, sound.TimePosition) -- 一時停止 false 10
task.wait(3)
sound:Resume()
print("再生", sound.Playing, sound.TimePosition) -- 再生 true 10
task.wait(3)
sound:Stop()
print("停止", sound.Playing, sound.TimePosition) -- 停止 false 0
task.wait(3)
sound:Play()
print("再生", sound.Playing, sound.TimePosition) -- 再生 true 0

pause
非推奨

Play
機能: LegacySound
Sound:Play():()
戻り値
()
コードサンプル
サウンド関数
-- サウンドを作成する
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://9120386436"
if not sound.IsLoaded then
sound.Loaded:Wait()
end
-- イベントをリッスンする
sound.Played:Connect(function(_soundId)
print("Sound.Played イベント")
end)
sound.Paused:Connect(function(_soundId)
print("Sound.Paused イベント")
end)
sound.Resumed:Connect(function(_soundId)
print("Sound.Resumed イベント")
end)
sound.Stopped:Connect(function(_soundId)
print("Sound.Stopped イベント")
end)
sound:Play()
print("再生", sound.Playing, sound.TimePosition) -- 再生 true 0
task.wait(10)
sound:Pause()
print("一時停止", sound.Playing, sound.TimePosition) -- 一時停止 false 10
task.wait(3)
sound:Resume()
print("再生", sound.Playing, sound.TimePosition) -- 再生 true 10
task.wait(3)
sound:Stop()
print("停止", sound.Playing, sound.TimePosition) -- 停止 false 0
task.wait(3)
sound:Play()
print("再生", sound.Playing, sound.TimePosition) -- 再生 true 0

play
非推奨

Resume
機能: LegacySound
Sound:Resume():()
戻り値
()
コードサンプル
サウンド関数
-- サウンドを作成する
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://9120386436"
if not sound.IsLoaded then
sound.Loaded:Wait()
end
-- イベントをリッスンする
sound.Played:Connect(function(_soundId)
print("Sound.Played イベント")
end)
sound.Paused:Connect(function(_soundId)
print("Sound.Paused イベント")
end)
sound.Resumed:Connect(function(_soundId)
print("Sound.Resumed イベント")
end)
sound.Stopped:Connect(function(_soundId)
print("Sound.Stopped イベント")
end)
sound:Play()
print("再生", sound.Playing, sound.TimePosition) -- 再生 true 0
task.wait(10)
sound:Pause()
print("一時停止", sound.Playing, sound.TimePosition) -- 一時停止 false 10
task.wait(3)
sound:Resume()
print("再生", sound.Playing, sound.TimePosition) -- 再生 true 10
task.wait(3)
sound:Stop()
print("停止", sound.Playing, sound.TimePosition) -- 停止 false 0
task.wait(3)
sound:Play()
print("再生", sound.Playing, sound.TimePosition) -- 再生 true 0

Stop
機能: LegacySound
Sound:Stop():()
戻り値
()
コードサンプル
サウンド関数
-- サウンドを作成する
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://9120386436"
if not sound.IsLoaded then
sound.Loaded:Wait()
end
-- イベントをリッスンする
sound.Played:Connect(function(_soundId)
print("Sound.Played イベント")
end)
sound.Paused:Connect(function(_soundId)
print("Sound.Paused イベント")
end)
sound.Resumed:Connect(function(_soundId)
print("Sound.Resumed イベント")
end)
sound.Stopped:Connect(function(_soundId)
print("Sound.Stopped イベント")
end)
sound:Play()
print("再生", sound.Playing, sound.TimePosition) -- 再生 true 0
task.wait(10)
sound:Pause()
print("一時停止", sound.Playing, sound.TimePosition) -- 一時停止 false 10
task.wait(3)
sound:Resume()
print("再生", sound.Playing, sound.TimePosition) -- 再生 true 10
task.wait(3)
sound:Stop()
print("停止", sound.Playing, sound.TimePosition) -- 停止 false 0
task.wait(3)
sound:Play()
print("再生", sound.Playing, sound.TimePosition) -- 再生 true 0

stop
非推奨

イベント
DidLoop
機能: LegacySound
Sound.DidLoop(
soundId:string, numOfTimesLooped:number
パラメータ
soundId:string
numOfTimesLooped:number
コードサンプル
指定した回数だけループする
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
-- 接続を切断します
connection:Disconnect()
-- 音を停止します
sound:Stop()
end
end)
sound:Play()
end
end
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://0"
loopNTimes(sound, 5)

Ended
機能: LegacySound
Sound.Ended(soundId:string):RBXScriptSignal
パラメータ
soundId:string

Loaded
機能: LegacySound
Sound.Loaded(soundId:string):RBXScriptSignal
パラメータ
soundId:string
コードサンプル
サウンドを読み込む
local sound = script.Parent.Sound
if not sound.IsLoaded then
sound.Loaded:Wait()
end
print("サウンドが読み込まれました!")

Paused
機能: LegacySound
Sound.Paused(soundId:string):RBXScriptSignal
パラメータ
soundId:string
コードサンプル
サウンド関数
-- サウンドを作成する
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://9120386436"
if not sound.IsLoaded then
sound.Loaded:Wait()
end
-- イベントをリッスンする
sound.Played:Connect(function(_soundId)
print("Sound.Played イベント")
end)
sound.Paused:Connect(function(_soundId)
print("Sound.Paused イベント")
end)
sound.Resumed:Connect(function(_soundId)
print("Sound.Resumed イベント")
end)
sound.Stopped:Connect(function(_soundId)
print("Sound.Stopped イベント")
end)
sound:Play()
print("再生", sound.Playing, sound.TimePosition) -- 再生 true 0
task.wait(10)
sound:Pause()
print("一時停止", sound.Playing, sound.TimePosition) -- 一時停止 false 10
task.wait(3)
sound:Resume()
print("再生", sound.Playing, sound.TimePosition) -- 再生 true 10
task.wait(3)
sound:Stop()
print("停止", sound.Playing, sound.TimePosition) -- 停止 false 0
task.wait(3)
sound:Play()
print("再生", sound.Playing, sound.TimePosition) -- 再生 true 0

Played
機能: LegacySound
Sound.Played(soundId:string):RBXScriptSignal
パラメータ
soundId:string
コードサンプル
サウンド関数
-- サウンドを作成する
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://9120386436"
if not sound.IsLoaded then
sound.Loaded:Wait()
end
-- イベントをリッスンする
sound.Played:Connect(function(_soundId)
print("Sound.Played イベント")
end)
sound.Paused:Connect(function(_soundId)
print("Sound.Paused イベント")
end)
sound.Resumed:Connect(function(_soundId)
print("Sound.Resumed イベント")
end)
sound.Stopped:Connect(function(_soundId)
print("Sound.Stopped イベント")
end)
sound:Play()
print("再生", sound.Playing, sound.TimePosition) -- 再生 true 0
task.wait(10)
sound:Pause()
print("一時停止", sound.Playing, sound.TimePosition) -- 一時停止 false 10
task.wait(3)
sound:Resume()
print("再生", sound.Playing, sound.TimePosition) -- 再生 true 10
task.wait(3)
sound:Stop()
print("停止", sound.Playing, sound.TimePosition) -- 停止 false 0
task.wait(3)
sound:Play()
print("再生", sound.Playing, sound.TimePosition) -- 再生 true 0

Resumed
機能: LegacySound
Sound.Resumed(soundId:string):RBXScriptSignal
パラメータ
soundId:string
コードサンプル
サウンド関数
-- サウンドを作成する
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://9120386436"
if not sound.IsLoaded then
sound.Loaded:Wait()
end
-- イベントをリッスンする
sound.Played:Connect(function(_soundId)
print("Sound.Played イベント")
end)
sound.Paused:Connect(function(_soundId)
print("Sound.Paused イベント")
end)
sound.Resumed:Connect(function(_soundId)
print("Sound.Resumed イベント")
end)
sound.Stopped:Connect(function(_soundId)
print("Sound.Stopped イベント")
end)
sound:Play()
print("再生", sound.Playing, sound.TimePosition) -- 再生 true 0
task.wait(10)
sound:Pause()
print("一時停止", sound.Playing, sound.TimePosition) -- 一時停止 false 10
task.wait(3)
sound:Resume()
print("再生", sound.Playing, sound.TimePosition) -- 再生 true 10
task.wait(3)
sound:Stop()
print("停止", sound.Playing, sound.TimePosition) -- 停止 false 0
task.wait(3)
sound:Play()
print("再生", sound.Playing, sound.TimePosition) -- 再生 true 0

Stopped
機能: LegacySound
Sound.Stopped(soundId:string):RBXScriptSignal
パラメータ
soundId:string
コードサンプル
サウンド関数
-- サウンドを作成する
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://9120386436"
if not sound.IsLoaded then
sound.Loaded:Wait()
end
-- イベントをリッスンする
sound.Played:Connect(function(_soundId)
print("Sound.Played イベント")
end)
sound.Paused:Connect(function(_soundId)
print("Sound.Paused イベント")
end)
sound.Resumed:Connect(function(_soundId)
print("Sound.Resumed イベント")
end)
sound.Stopped:Connect(function(_soundId)
print("Sound.Stopped イベント")
end)
sound:Play()
print("再生", sound.Playing, sound.TimePosition) -- 再生 true 0
task.wait(10)
sound:Pause()
print("一時停止", sound.Playing, sound.TimePosition) -- 一時停止 false 10
task.wait(3)
sound:Resume()
print("再生", sound.Playing, sound.TimePosition) -- 再生 true 10
task.wait(3)
sound:Stop()
print("停止", sound.Playing, sound.TimePosition) -- 停止 false 0
task.wait(3)
sound:Play()
print("再生", sound.Playing, sound.TimePosition) -- 再生 true 0

©2026 Roblox Corporation。Roblox(ロブロックス)、RobloxロゴおよびPowering Imaginationは、米国並びにその他の国における登録商標および非登録商標です。