Sound

非推奨を表示

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

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.

Music Playing Part

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)

概要

プロパティ

  • 読み取り専用
    複製されていません
    閲覧できません
    Robloxのスクリプトセキュリティ
    並列読み取り
  • 読み取り専用
    複製されていません
    並列読み取り

    このプロパティは、true が Roblox サーバーからロードされ、プレイできる準備が整ったときに Sound です。

  • 非表示
    読み取り専用
    複製されていません
    並列読み取り

    プレイしていないときに を返す読み取り専用プロパティ。

  • 非表示
    読み取り専用
    複製されていません
    並列読み取り

    プレイ中の が返す読み取り専用プロパティ。

  • 並列読み取り

    PlaybackRegion 内の希望のループ開始とループ終了を示す範囲、秒単位。

  • 並列読み取り

    Sound が再生終了後に繰り返されるかどうかを設定します。

  • 並列読み取り

    When true 、エクスペリエンスから削除されると、Sound が再生されます。

  • 読み取り専用
    複製されていません
    並列読み取り

    01000 の間の数字は、現在 Sound がどれほど大声で戻る生されているかを示します。

  • 並列読み取り

    TimeLength 内の希望の開始と終了時間を示す範囲、秒単位。

  • If true 、このプロパティは、Sound の再生をより正確に制御できる PlaybackRegion および LoopRegion プロパティへのアクセスを提供します。

  • 複製されていません
    並列読み取り

    Sound が再生する速度を決定し、高い値ではサウンドが速くプレイ生し、高いピッチで再生します。

  • 複製されていません
    並列読み取り

    現在 Sound が再生中かどうかを示します。

  • 並列読み取り

    クライアントのリスナーの最大距離、スタッドで、サウンドの起源から聞こえることができます。対象は、Sounds 親に属する BasePart または Attachment のみです。

  • 並列読み取り

    親に属する Sound または BasePart または Attachment の 最小距離、スタッドで、 が低下し始める距離 (ボリュームが減少する)。

  • 並列読み取り

    親に属する Sound または BasePart または Attachment のボリュームの量が、リスナーと親の間の距離が変化するにつれて衰減する方法を制御します。

  • 並列読み取り

    この SoundGroup にリンクされている Sound

  • SoundId:ContentId
    並列読み取り

    Sound に関連付けるサウンドファイルのコンテンツID。

  • 読み取り専用
    複製されていません
    並列読み取り

    秒ごとの Sound の長さ。

  • 複製されていません
    並列読み取り

    秒ごとの Sound の進行状況。Sound の再生位置を移動する前と再生中の両方を変更できます。

  • 並列読み取り

    Sound のボリューム。

方法

イベント

プロパティ

ChannelCount

読み取り専用
複製されていません
閲覧できません
Robloxのスクリプトセキュリティ
並列読み取り

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.

Load Sound

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.

Sound IsPlaying and SoundIsPaused

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.

Sound IsPlaying and SoundIsPaused

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 内の希望のループ開始とループ終了を示す範囲、秒単位。

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.

Loop a Number of Times

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

読み取り専用
複製されていません
並列読み取り

01000 の間の数字は、現在 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.

Volume Amplitude Bar

-- 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 内の希望の開始と終了時間を示す範囲、秒単位。

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.

Sound PlaybackSpeed

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 の プロパティ ウィンドウで、 編集 モードで、Playingtrue に切り替えると、サウンドが再生開始しませんが、サウンドは実行中に再生開始します。

このプロパティは、読み込み専用のプロパティである IsPlaying と混同してはならない。

Note that when Playingfalse に設定されると、サウンドの 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.

Sound Playing

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 を参照してください。

SoundGroup

並列読み取り

この SoundGroup にリンクされている Sound

SoundId

ContentId
並列読み取り

このプロパティは、Sound に関連付けるサウンドファイルのコンテンツIDです。詳細は、オーディオアセット を参照してください。

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.

Play a Sound for a Specific Duration

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 の速度で増加します。一度、TimePositionTimeLength に到達すると、サウンドは停止しない限り、Looped ではありません。

ループトラックの長さより大きな値に設定する TimePosition を設定すると、包まれることはありません。その動作が望ましい場合は、次のコードスニペットを考えてください:


local newPosition = 1.5
if newPosition >= sound.TimeLength then
newPosition = newPosition - sound.TimeLength
end
sound.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).

Sound TimePosition

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 のボリューム。010 の間で設定でき、デフォルトは 0.5 です。

注: SoundSoundGroup のメンバーである場合、その再生ボリューム (但し、その Volume プロパティではない) はグループの SoundGroup.Volume プロパティに影響を受けます。

方法

Pause

()

このメソッドは、再生を一時停止し、Sound を再生し、Playingfalse に設定します。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.

Sound Functions

-- 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.

Sound Functions

-- 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 を再開し、Playingtrue に設定します。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.

Sound Functions

-- 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 を停止し、Playingfalse に設定し、TimePosition0 に設定します。


戻り値

()

コードサンプル

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.

Sound Functions

-- 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 ループが発動するたびに発火します。soundIdnumOfTimesLooped を返し、それぞれサウンドのコンテンツIDとループ回数を指定します。

When the Sound is stopped through Stop() , the looped counter resets meaning the next DidLoop event will return 1 for numOfTimesLooped .

パラメータ

soundId: string

ループした SoundIdSound

numOfTimesLooped: number

Sound がループした回数。


コードサンプル

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.

Loop a Number of Times

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 イベントを使用します。

パラメータ

soundId: string

終了した SoundIdSound


Loaded

Sound がロードされると発火します。

このイベントはサウンドがロードされる時にのみ発動するため、このイベントに接続する前にサウンドの IsLoaded プロパティをチェックすることをお勧めします。

パラメータ

soundId: string

ロードされた SoundIdSound


コードサンプル

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.

Load Sound

local sound = script.Parent.Sound
if not sound.IsLoaded then
sound.Loaded:Wait()
end
print("The sound has loaded!")

Paused

ファイアは、 を使用して一時停止すると、いつでも発生します。

パラメータ

soundId: string

一時停止した SoundIdSound


コードサンプル

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.

Sound Functions

-- 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

ファイアは、 を使用して再生されるときにいつでも発生します。このイベントは、 が設定されているため、 が再生されず、 が破壊され、 が設定されているため、このイベントは発火しません。

パラメータ

soundId: string

再生された SoundIdSound


コードサンプル

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.

Sound Functions

-- 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() で発火します。

パラメータ

soundId: string

The SoundIdSound が再開されています。


コードサンプル

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.

Sound Functions

-- 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() が再生中にサウンドを破壊すると、このイベントが発火します。再生中にサウンドを破壊すると、このイベントが発火します。

パラメータ

soundId: string

停止した SoundIdSound


コードサンプル

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.

Sound Functions

-- 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