Sound は、音を発しているオブジェクトです。このオブジェクトは、BasePart または Attachment に配置されると、その部分の BasePart.Position または付属の Attachment.WorldPosition からサウンドを発します。この配置では、Sound がドップラー効果を展示し、その周波数とピッチは、付属のどのアタッチメントやパーツに相対する動作によって変化します。さらに、ボリュームは、クライアントのサウンドリスナー (デフォルトでは Camera 位置) とサウンドの親の位置の距離によって決まります。詳しくは、RollOffMode を参照してください。
サウンドは、 親になっていない 、または BasePart または Attachment に属していない場合、「グローバル」と考えられます。この場合、サウンドは全体の場プレース全体で同じ音量で再生します。
コードサンプル
The code in this sample demonstrates how a sound parented to a Part or Attachment will play locally and experience volume drop off the further the player's camera is away from the part.
A part is instanced, and a sound is instanced and parented to the part. A click detector is set up on the part that will check if the sound is playing, using Sound.IsPlaying and play or stop the sound depending.
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
-- create a sound
local sound = Instance.new("Sound", part)
sound.SoundId = "rbxassetid://9120386436"
sound.EmitterSize = 5 -- decrease the emitter size (for earlier volume drop off)
sound.Looped = true
sound.Parent = part
local clickDetector = Instance.new("ClickDetector")
clickDetector.Parent = part
-- toggle the sound playing / not playing
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)
概要
プロパティ
このプロパティは、true が Roblox サーバーからロードされ、プレイできる準備が整ったときに Sound です。
プレイしていないときに を返す読み取り専用プロパティ。
プレイ中の が返す読み取り専用プロパティ。
PlaybackRegion 内の希望のループ開始とループ終了を示す範囲、秒単位。
Sound が再生終了後に繰り返されるかどうかを設定します。
When true 、エクスペリエンスから削除されると、Sound が再生されます。
0 と 1000 の間の数字は、現在 Sound がどれほど大声で戻る生されているかを示します。
TimeLength 内の希望の開始と終了時間を示す範囲、秒単位。
If true 、このプロパティは、Sound の再生をより正確に制御できる PlaybackRegion および LoopRegion プロパティへのアクセスを提供します。
Sound が再生する速度を決定し、高い値ではサウンドが速くプレイ生し、高いピッチで再生します。
現在 Sound が再生中かどうかを示します。
クライアントのリスナーの最大距離、スタッドで、サウンドの起源から聞こえることができます。対象は、Sounds 親に属する BasePart または Attachment のみです。
親に属する Sound または BasePart または Attachment の 最小距離、スタッドで、 が低下し始める距離 (ボリュームが減少する)。
親に属する Sound または BasePart または Attachment のボリュームの量が、リスナーと親の間の距離が変化するにつれて衰減する方法を制御します。
この SoundGroup にリンクされている Sound 。
Sound に関連付けるサウンドファイルのコンテンツID。
秒ごとの Sound の長さ。
Sound のボリューム。
方法
イベント
プロパティ
ChannelCount
IsLoaded
このプロパティは、true が Roblox サーバーからロードされ、プレイできる準備が整ったときに Sound です。このプロパティと Loaded イベントを使用して、サウンドを再生する前にロードされたかどうかを確認できます。
コードサンプル
This simple function will verify a Sound has loaded by checking the Sound.IsLoaded property. If Sound.IsLoaded is false it will wait for the Loaded event before resuming.
It is important to check Sound.IsLoaded before connecting to the Sound.Loaded event, as if the sound has already loaded the Sound.Loaded event will not fire and the function will yield indefinitely.
local sound = script.Parent.Sound
if not sound.IsLoaded then
sound.Loaded:Wait()
end
print("The sound has loaded!")
IsPaused
この読み込み専用プロパティは、Sound が再生していないときに true を返します。サウンドが true を使用して一時停止された場合、Pause() を使用して停止された場合、またはサウンドが再生されたことがない場合は、Stop() を使用して返すことができます。
As IsPaused は読み取り専用であるため、サウンドを停止するために使用することはできません; Stop() または Pause() の代わりに使用する必要があります。
コードサンプル
This code sample contains demonstrates when the Sound.IsPlaying and Sound.IsPaused properties will be true or false.
A sound is instanced in the Workspace and the Sound.IsLoaded property is checked to ensure it has loaded, if it has not the Sound.Loaded event is used to yield the script until the sound has.
As the sound is played, paused and stopped the Sound.IsPlaying and Sound.IsPaused properties are printed to demonstrate how they respond to each of these functions. Note Sound.IsPaused will always be true if even if the sound has been stopped rather than paused.
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
この読み込み専用プロパティは、Sound が再生されているときに真を返します。
As IsPlaying は読み取り専用であるため、サウンドを再生するために使用することはできません; Play() の代わりに使用する必要があります。
コードサンプル
This code sample contains demonstrates when the Sound.IsPlaying and Sound.IsPaused properties will be true or false.
A sound is instanced in the Workspace and the Sound.IsLoaded property is checked to ensure it has loaded, if it has not the Sound.Loaded event is used to yield the script until the sound has.
As the sound is played, paused and stopped the Sound.IsPlaying and Sound.IsPaused properties are printed to demonstrate how they respond to each of these functions. Note Sound.IsPaused will always be true if even if the sound has been stopped rather than paused.
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
LoopRegion
PlaybackRegion 内の希望のループ開始とループ終了を示す範囲、秒単位。
If LoopRegion.Min > PlaybackRegion.Min 、ループは LoopRegion.Min から始まります。
If LoopRegion.Min < PlaybackRegion.Min 、ループは PlaybackRegion.Min から始まります。
If LoopRegion.Max > PlaybackRegion.Max 、ループは PlaybackRegion.Max で始まります。
If LoopRegion.Max < PlaybackRegion.Max 、ループはその時点で 正確に 始まります。
If LoopRegion.Min == LoopRegion.Max , the Sound は代わりに PlaybackRegion プロパティを使用します。
Looped
これは、Sound が再生終了後に繰り返されるかどうかを設定します。ループされたサウンドは、音楽やバックグラウンドの環境音など、さまざまなアプリケーションに適しています。
DidLoop イベントは、サウンドがループした回数を追跡するのに使用できます。
コードサンプル
This code sample includes a function that will play a sound and allow it to loop for a given number of times before stopping it.
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
-- disconnect the connection
connection:Disconnect()
-- stop the sound
sound:Stop()
end
end)
sound:Play()
end
end
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://0"
loopNTimes(sound, 5)
PlayOnRemove
When true , the Sound は、Sound またはその祖先が nil からエクスペリエンスを削除されると、再生されます。これは、次のすべてが PlayOnRemove になると、サウンドが再生することを意味します: true :
- sound:Destroy()
- sound.Parent = nil
- sound.Parent.Parent = nil
PlaybackLoudness
0 と 1000 の間の数字は、現在 Sound がどれほど大声で再戻るされているかを示します。このプロパティは、既読み込まれた時刻のインスタンスでのサウンドの再生幅を反映します。
コードサンプル
In this sample Sound.PlaybackLoudness is used to create an amplitude bar that shows the amplitude of a sound playing.
This code sample should be placed in StarterPlayerScripts.
A simple GUI is created, a frame holding that bar and a frame containing the bar. A Sound is then played and the size of the bar is set to reflect the Sound.PlaybackLoudness on a loop.
-- to be placed in StarterPlayer > StarterPlayerScripts
local Players = game:GetService("Players")
-- wait for local player PlayerGui
local LocalPlayer = Players.LocalPlayer
local playerGui = LocalPlayer:WaitForChild("PlayerGui")
-- create a ScreenGui
local screenGui = Instance.new("ScreenGui")
screenGui.Parent = playerGui
-- create a holder for our bar
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
-- create a bar
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
-- create a sound
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://9120386436"
sound.Looped = true
sound.Parent = screenGui
sound:Play()
-- define a max loudness
local maxLoudness = 30
-- animate the amplitude bar
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
TimeLength 内の希望の開始と終了時間を示す範囲、秒単位。
If PlaybackRegion.Min > 0 、サウンドは PlaybackRegion.Min 時から再生開始します。
If PlaybackRegion.Min < 0 、サウンドは 0 から再生開始します。
If PlaybackRegion.Max > Sound.TimeLength 、サウンドは Sound.TimeLength で停止します。
If PlaybackRegion.Max < Sound.TimeLength , サウンドはその時点で停止します 正確に 。
If PlaybackRegion.Min == PlaybackRegion.Max 、このプロパティは非アクティブです。
PlaybackRegionsEnabled
If true 、このプロパティは、Sound の再生をより正確に制御できる PlaybackRegion および LoopRegion プロパティへのアクセスを提供します。
PlaybackSpeed
Sound が再生する速度を決定し、高い値ではサウンドが速くプレイ生し、高いピッチで再生します。
コードサンプル
In this example a Sound is played in the Workspace. The PlaybackSpeed property is increased and decreased at intervals to demonstrate its impact on the playback of the Sound.
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://9120386436"
sound.Looped = true
sound.Parent = workspace
sound:Play()
task.wait(10)
sound.PlaybackSpeed = 3 -- 3x faster
task.wait(5)
sound.PlaybackSpeed = 0.5 -- 2x slower
task.wait(5)
sound.PlaybackSpeed = 1 -- default
Playing
現在 Sound が再生されているかどうかを示します。これは切り替え可能であり、このプロパティは常に複製されます。
Studio の プロパティ ウィンドウで、 編集 モードで、Playing を true に切り替えると、サウンドが再生開始しませんが、サウンドは実行中に再生開始します。
このプロパティは、読み込み専用のプロパティである IsPlaying と混同してはならない。
Note that when Playing が false に設定されると、サウンドの TimePosition プロパティはリセットされず、つまり、Playing が再び true に設定されると、オーディオは停止時の時間位置から継続します。しかし、Play() 機能を使用してサウンドを再開すると、時間位置が 0 にリセットされます。
コードサンプル
This sample demonstrates how the Sound.Playing property can be used to start and stop playback of a sound.
A sound is instanced in the Workspace and playback is started by setting Sound.Playing to true. After ten seconds the playback is stopped by setting Sound.Playing to false. When the playback is again resumed using Sound.Playing it resumes at the previous Sound.TimePosition it was stopped at. This is demonstrated by printing the TimePosition property immediately after resuming the sound.
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://9120386436"
sound.Looped = true
sound.Parent = workspace
print("playing sound")
sound.Playing = true
task.wait(10)
print("stopping sound")
sound.Playing = false
task.wait(5)
sound.Playing = true
local timePosition = sound.TimePosition
print("resumed at time position: " .. tostring(timePosition)) -- c. 10 seconds
RollOffMaxDistance
クライアントのリスナーの最大距離、スタッドで、サウンドの起源から聞こえることができます。対象は、Sounds 親に属する BasePart または Attachment のみです。
どのように RollOffMaxDistance がサウンドの消滅 (消滅する方法) に影響するかは、RollOffMode プロパティに依存します。
RollOffMinDistance
親に属する Sound または BasePart または Attachment の 最小距離、スタッドで、 が低下し始める距離 (ボリュームが減少する)。
どのように RollOffMinDistance がサウンドの消滅 (消滅する方法) に影響するかは、RollOffMode プロパティに依存します。
RollOffMode
このプロパティは、親に属する Sound または BasePart または Attachment のボリュームが、リスナーと親の間の距離が変更されるとどのように軽減するかを制御します。
詳細は、Enum.RollOffMode を参照してください。
TimeLength
秒ごとの Sound の長さ。Sound がロードされていない場合、この値は 0 になります。
このプロパティは、PlaybackSpeed と一緒に使用されることが多く、特定の期間続くサウンドの速度を調整します。
コードサンプル
This code sample includes a simple function that uses Sound.TimeLength and Sound.PlaybackSpeed to play a sound that'll take the given duration to complete. It achieves this by setting the PlaybackSpeed of the sound to be equal to the TimeLength of the sound divided by the desired duration.
Note that as TimeLength is equal to 0 when the sound has not loaded, the function will yield while it loads the sound.
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
このプロパティは、秒ごとの Sound の進行状況を反映します。再生位置を、再生前と再生中の両方で変更できます。
As a Sound が再生されると、TimePosition は秒ごとに PlaybackSpeed の速度で増加します。一度、TimePosition が TimeLength に到達すると、サウンドは停止しない限り、Looped ではありません。
ループトラックの長さより大きな値に設定する TimePosition を設定すると、包まれることはありません。その動作が望ましい場合は、次のコードスニペットを考えてください:
local newPosition = 1.5if newPosition >= sound.TimeLength thennewPosition = newPosition - sound.TimeLengthendsound.TimePosition = newPosition
コードサンプル
This sample demonstrates how Sound.TimePosition can be used to jump to particular points in an audio file both before and during Sound playback.
A Sound is created in the Workspace and set to start at 30 seconds in. During playback, it jumps forwards to 100 seconds and then back to the start (0 seconds).
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
Sound のボリューム。0 と 10 の間で設定でき、デフォルトは 0.5 です。
注: Sound が SoundGroup のメンバーである場合、その再生ボリューム (但し、その Volume プロパティではない) はグループの SoundGroup.Volume プロパティに影響を受けます。
方法
Pause
このメソッドは、再生を一時停止し、Sound を再生し、Playing を false に設定します。Stop() とは異なり、TimePosition をリセットしません、つまりサウンドは Resume() を使用して再開できます。
戻り値
コードサンプル
This sample gives a simple demonstration of what each of the Sound functions (Sound.Play, Sound.Stop, Sound.Pause and Sound.Resume) do to Sound.Playing and Sound.TimePosition.
-- create a sound
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://9120386436"
if not sound.IsLoaded then
sound.Loaded:Wait()
end
-- listen for events
sound.Played:Connect(function(_soundId)
print("Sound.Played event")
end)
sound.Paused:Connect(function(_soundId)
print("Sound.Paused event")
end)
sound.Resumed:Connect(function(_soundId)
print("Sound.Resumed event")
end)
sound.Stopped:Connect(function(_soundId)
print("Sound.Stopped event")
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
このメソッドは、 を再生し、 をスクリプトによって設定された最後の値に設設定するし、 を に設定します。
戻り値
コードサンプル
This sample gives a simple demonstration of what each of the Sound functions (Sound.Play, Sound.Stop, Sound.Pause and Sound.Resume) do to Sound.Playing and Sound.TimePosition.
-- create a sound
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://9120386436"
if not sound.IsLoaded then
sound.Loaded:Wait()
end
-- listen for events
sound.Played:Connect(function(_soundId)
print("Sound.Played event")
end)
sound.Paused:Connect(function(_soundId)
print("Sound.Paused event")
end)
sound.Resumed:Connect(function(_soundId)
print("Sound.Resumed event")
end)
sound.Stopped:Connect(function(_soundId)
print("Sound.Stopped event")
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
Resume
このメソッドは、Sound を再開し、Playing を true に設定します。TimePosition を変更しないため、Pause() で一時停止したサウンドの再生を再開するのに使用できます。
戻り値
コードサンプル
This sample gives a simple demonstration of what each of the Sound functions (Sound.Play, Sound.Stop, Sound.Pause and Sound.Resume) do to Sound.Playing and Sound.TimePosition.
-- create a sound
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://9120386436"
if not sound.IsLoaded then
sound.Loaded:Wait()
end
-- listen for events
sound.Played:Connect(function(_soundId)
print("Sound.Played event")
end)
sound.Paused:Connect(function(_soundId)
print("Sound.Paused event")
end)
sound.Resumed:Connect(function(_soundId)
print("Sound.Resumed event")
end)
sound.Stopped:Connect(function(_soundId)
print("Sound.Stopped event")
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
このメソッドは Sound を停止し、Playing を false に設定し、TimePosition を 0 に設定します。
戻り値
コードサンプル
This sample gives a simple demonstration of what each of the Sound functions (Sound.Play, Sound.Stop, Sound.Pause and Sound.Resume) do to Sound.Playing and Sound.TimePosition.
-- create a sound
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://9120386436"
if not sound.IsLoaded then
sound.Loaded:Wait()
end
-- listen for events
sound.Played:Connect(function(_soundId)
print("Sound.Played event")
end)
sound.Paused:Connect(function(_soundId)
print("Sound.Paused event")
end)
sound.Resumed:Connect(function(_soundId)
print("Sound.Resumed event")
end)
sound.Stopped:Connect(function(_soundId)
print("Sound.Stopped event")
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
イベント
DidLoop
Sound ループが発動するたびに発火します。soundId と numOfTimesLooped を返し、それぞれサウンドのコンテンツIDとループ回数を指定します。
When the Sound is stopped through Stop() , the looped counter resets meaning the next DidLoop event will return 1 for numOfTimesLooped .
パラメータ
コードサンプル
This code sample includes a function that will play a sound and allow it to loop for a given number of times before stopping it.
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
-- disconnect the connection
connection:Disconnect()
-- stop the sound
sound:Stop()
end
end)
sound:Play()
end
end
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://0"
loopNTimes(sound, 5)
Ended
Sound が再生を完了し停止したときに発火します。このイベントは、再生が完了したときにサウンドを破壊するのによく使用されます:
sound:Play()sound.Ended:Wait()sound:Destroy()
このイベントは、終了すると 音を発射しないことに注意してください 、彼らは終了すると 設定された音を再生し続けます。このイベントは、再生が完了する前にサウンドが停止した場合も 発火しません ;この用途には Stopped イベントを使用します。
パラメータ
Loaded
Sound がロードされると発火します。
このイベントはサウンドがロードされる時にのみ発動するため、このイベントに接続する前にサウンドの IsLoaded プロパティをチェックすることをお勧めします。
パラメータ
コードサンプル
This simple function will verify a Sound has loaded by checking the Sound.IsLoaded property. If Sound.IsLoaded is false it will wait for the Loaded event before resuming.
It is important to check Sound.IsLoaded before connecting to the Sound.Loaded event, as if the sound has already loaded the Sound.Loaded event will not fire and the function will yield indefinitely.
local sound = script.Parent.Sound
if not sound.IsLoaded then
sound.Loaded:Wait()
end
print("The sound has loaded!")
Paused
ファイアは、 を使用して一時停止すると、いつでも発生します。
パラメータ
コードサンプル
This sample gives a simple demonstration of what each of the Sound functions (Sound.Play, Sound.Stop, Sound.Pause and Sound.Resume) do to Sound.Playing and Sound.TimePosition.
-- create a sound
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://9120386436"
if not sound.IsLoaded then
sound.Loaded:Wait()
end
-- listen for events
sound.Played:Connect(function(_soundId)
print("Sound.Played event")
end)
sound.Paused:Connect(function(_soundId)
print("Sound.Paused event")
end)
sound.Resumed:Connect(function(_soundId)
print("Sound.Resumed event")
end)
sound.Stopped:Connect(function(_soundId)
print("Sound.Stopped event")
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
ファイアは、 を使用して再生されるときにいつでも発生します。このイベントは、 が設定されているため、 が再生されず、 が破壊され、 が設定されているため、このイベントは発火しません。
パラメータ
コードサンプル
This sample gives a simple demonstration of what each of the Sound functions (Sound.Play, Sound.Stop, Sound.Pause and Sound.Resume) do to Sound.Playing and Sound.TimePosition.
-- create a sound
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://9120386436"
if not sound.IsLoaded then
sound.Loaded:Wait()
end
-- listen for events
sound.Played:Connect(function(_soundId)
print("Sound.Played event")
end)
sound.Paused:Connect(function(_soundId)
print("Sound.Paused event")
end)
sound.Resumed:Connect(function(_soundId)
print("Sound.Resumed event")
end)
sound.Stopped:Connect(function(_soundId)
print("Sound.Stopped event")
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
Sound を使用して再開すると、Resume() で発火します。
パラメータ
コードサンプル
This sample gives a simple demonstration of what each of the Sound functions (Sound.Play, Sound.Stop, Sound.Pause and Sound.Resume) do to Sound.Playing and Sound.TimePosition.
-- create a sound
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://9120386436"
if not sound.IsLoaded then
sound.Loaded:Wait()
end
-- listen for events
sound.Played:Connect(function(_soundId)
print("Sound.Played event")
end)
sound.Paused:Connect(function(_soundId)
print("Sound.Paused event")
end)
sound.Resumed:Connect(function(_soundId)
print("Sound.Resumed event")
end)
sound.Stopped:Connect(function(_soundId)
print("Sound.Stopped event")
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
Sound を使用して停止すると、Stop() が再生中にサウンドを破壊すると、このイベントが発火します。再生中にサウンドを破壊すると、このイベントが発火します。
パラメータ
コードサンプル
This sample gives a simple demonstration of what each of the Sound functions (Sound.Play, Sound.Stop, Sound.Pause and Sound.Resume) do to Sound.Playing and Sound.TimePosition.
-- create a sound
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://9120386436"
if not sound.IsLoaded then
sound.Loaded:Wait()
end
-- listen for events
sound.Played:Connect(function(_soundId)
print("Sound.Played event")
end)
sound.Paused:Connect(function(_soundId)
print("Sound.Paused event")
end)
sound.Resumed:Connect(function(_soundId)
print("Sound.Resumed event")
end)
sound.Stopped:Connect(function(_soundId)
print("Sound.Stopped event")
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