Sound

非推奨を表示

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

Class.Sound は、音を発生させるオブジェクトです。

2D と 3D サウンド

サウンドを Attachment または BasePart.Position の中に配置すると、そのパーツ

サウンドが 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)

This sample gives a simple example of how a Sound that is not parented to a Part or Attachment will play at a constant volume throughout the place. A sound is instanced and parented to the Workspace, and then played.

Sound in the Workspace

local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://9120386436"
sound.Looped = true
sound.Parent = workspace
sound:Play()

概要

プロパティ

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

    このプロパティは、Sound が Roblox サーバーから読み込まれ、プレイする準備ができたときに true になります。

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

    この読み取りのみのプロパティは、Sound がプレイしていないときに true を返します。

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

    この読み取りのみのプロパティは、Sound が再生するときに true を返します。

  • 並列読み取り

    Class.Sound.PlaybackRegion の中で、Class.Sound.Playback の開始と終了を指定した範囲。Class.Sound.Playback の中で、1>Class.Sound.Playback1> の開始と終了を指定した範囲。 Japanese:Class.Sound.PlaybackRegion の中で、Class.Sound.Playback の開始と終了を指定した範囲。Class.Sound.Playback の中で、1>Class.Sound.Playback1> の開始と終了を指定した範囲。

  • 並列読み取り

    これは、Sound がプレイしたときに繰り返すかどうかを設定します。

  • 並列読み取り

    Class.Sound がゲームから削除されると、Sound またはその先祖を nul にすることでプレイします。

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

    0 から 1000 の間の数字は、Sound が現在どれくらいうるさいかを示していま戻る。

  • 並列読み取り

    Class.Sound.TimeLength の中で、開始時間 (min) と停止時間 (max) を指定した範囲、秒単位で。

  • 並列読み取り

    true タグが付いている場合、このプロパティは、Sound アクセスを、Sound.PlaybackRegion および 1> Class.Sound.LoopRegion 1> プロパティに、より正確に制御できるようにします。

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

    Class.Sound がプレイする速度を決めます。これは、サウンドをより速く、より高いピッチでプレイするための値を上げます。

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

    Class.Sound が現在プレイしているかどうかを示します。

  • 並列読み取り

    クライアントのリスナーがSound\sのオリジンから最大距離を保ち、Part またはAttachment (3D サウンド) に親接されている場合でも、1> 最大距離を保ち、4> リスナーの距離4> を保ちます。

  • 並列読み取り

    3D Sound (直接の子供の Class.BasePart または Class.Attachment ) が始まる最小の距離 (ボリュームを減少する) で、弱まり始めます。

  • 並列読み取り

    3D Sound (親に Class.BasePart または Class.Attachment )のボリュームをコントロールすると、リスナーとサウンドの親が変更する距離を変更します。

  • 並列読み取り

    この SoundGroup にリンクされた Sound は、このサウンドグループに適用されたボリュームとサウンドエフェクトは、サウンドに通過します。サウンドは、1つのサウンドグループにしか存在できません。

  • SoundId:ContentId
    並列読み取り

    このプロパティは、Soundオブジェクトに関連するサウンドファイルのコンテンツIDです。サウンドが Robloxにアップロードされると、コンテンツID はアップロードされたサウンドの URL で見つけることができます。

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

    秒単位の Sound の長さ。Sound が読み込まれていない場合、この値は 0 になります。

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

    Class.Sound のプログレスを秒単位で表示します。プレイヤーポジションを変更して、プレイヤーのプレイ時にプレイヤーポジションを変更できます。

  • 並列読み取り

    Class.Sound のボリューム。デフォルトは 0 から 10 です。

方法

  • Pause():void

    Class.Sound.Playing を偽に設定します。これは、サウンドが再生されている場合、Sound の再生を一時停止させます。Sound.TimePosition がリセットされないと、1>Class.Sound1> が再開されます。

  • Play():void

    プレイする SoundSound.TimePosition を最後の Script (または 0 が設設定するされていない場合) に設定し、2>Class.Sound.Playing2> を true に設定します。

  • Resume():void

    Resumes the Sound . Sets Sound.Playing to true. Does not alter Sound.TimePosition and thus can be used to resume the playback of a sound stopped using 1> Class.Sound:Pause()1> .

  • Stop():void

    Class.Sound を停止します。 Class.Sound.Playing を偽に設定し、 Class.Sound.TimePosition を0に設定します。

イベント

プロパティ

ChannelCount

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

IsLoaded

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

このプロパティは、Sound が Roblox サーバーから読み込まれ、プレイする準備ができたときに true になります。

Roblox では、オーディオファイルはゲーム自体に保存されていませんが、Roblox サーバーにホストされ、Sound.SoundId プロパティによって参照されます。これにより、オーディオを再生する前にクライアントのデバイスにダウンロードする必要があります。これには、ユーザ

開発者は、Sound.IsLoaded プロパティと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 を返します。このプロパティは、Sound:Pause() 関数を使用してサウンドを一時停止するか、Sound:Stop() 関数を使用してサウンドを永久に停止するときにのみ true を返します。

このプロパティは Sound.IsPlaying が偽であるときのみ真実です。

As IsPaused は読み取りのみなので、サウンドを停止するためには使用できません。Sound:Stop() およびSound: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 が再生するときに true を返します。

このプロパティは Sound.IsPaused が偽であるときのみ真実です。

As IsPlaying は読み取りのみなので、サウンドを再生するためには使用できません。Sound: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

並列読み取り

サウンドの Sound.PlaybackRegion 内の希望のループ開始とループ終了を表す範囲。

  • Class.Sound.PlaybackRegion|PlaybackRegion.Min から始まる場合、ループは PlaybackRegion.Min から始まります。

  • Class.Sound.PlaybackRegion|PlaybackRegion.Min から始まる場合、ループは Class.Sound.PlaybackRegion|PlaybackRegion.Min から始まります。

  • Class.Sound.PlaybackRegion|PlaybackRegion.Max の場合、ループは Class.Sound.PlaybackRegion|PlaybackRegion.Max から始まります。

  • Class.Sound.PlaybackRegion|PlaybackRegion.Max で、PlaybackRegion.Max の次のループが始まります。

  • Class.Sound.PlaybackRegion が LoopRegion.Max でする場合、Sound は代わりに 1>Class.Sound.PlaybackRegion1> プロパティを使用します。

Looped

並列読み取り

これは、Sound がプレイしたときに繰り返すかどうかを設定します。

ループされた音は、音楽や背景のアンビエント音などのさまざまなアプリケーションに使用できます。Sound.DidLoop イベントを使用して、サウンドがループされた回数を追跡できます。

コードサンプル

Whilst looping is most appropriate for longer tracks such as music or ambient sounds, this sample demonstrates sound looping by creating the Roblox death sound in every character's head and looping it.

The Players.PlayerAdded and Player.CharacterAdded functions are used to detect new player characters. One a new character has been added a sound is created in their head. For demonstration purposes, the Sound.DidLoop function is used to show how the number of times a particular sound has looped can be tracked.

Sound Looping

local Players = game:GetService("Players")
local function onPlayerAdded(player)
local function onCharacterAdded(character)
-- wait for the head to be added
local head = character:WaitForChild("Head")
local sound = Instance.new("Sound")
sound.Name = "TestSound"
sound.SoundId = "rbxasset://sounds/uuhhh.mp3" -- oof
sound.Parent = head
sound.Looped = true
sound.DidLoop:Connect(function(_soundId, numOfTimesLooped)
print("oof! " .. tostring(numOfTimesLooped))
end)
sound:Play()
end
player.CharacterAdded:Connect(onCharacterAdded)
end
Players.PlayerAdded:Connect(onPlayerAdded)

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

並列読み取り

Class.Sound がゲームから削除されると、Class.Sound が再生されます。

Class.Sound またはその親の Sound プロパティが nulo に設定されると、サウンドが再生されます。これは、Instance:Destroy() またはその親のすべての以下が nulo に設定されている場合にすべての次の内容がサウンドを再生することを意味します。これには、<

サウンド:サウンドを破壊する。親 = なし サウンド = なし

コードサンプル

In this sample a sound is created in the workspace, PlayOnRemove is set to true and the sound is then destroyed.

As Sound.PlayOnRemove is true, the sound will play when it is removed.

Sound PlayOnRemove

local sound = Instance.new("Sound")
sound.Name = "TestSound"
sound.SoundId = "rbxasset://sounds/uuhhh.mp3" -- oof
sound.Parent = workspace
sound.PlayOnRemove = true
task.wait(3)
sound:Destroy()

PlaybackLoudness

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

0 から 1000 の間の数字は、Sound が現在どれくらいうるさいかを示していま戻る。

このプロパティは、サウンドの再生時間が既読み取られたインスタンスの幅度を反映します。つまり、ほとんどのサウンドは常に変動します。これにより、Roblox Studio プロパティウィンドウに 0 が表示されることがありますが、コマンドバーまたは Scripts でコードによって読み取られる場合、正しい

コードサンプル

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

並列読み取り

Class.Sound.TimeLength の中で、開始時間 (min) と停止時間 (max) を指定した範囲、秒単位で。

  • PlaybackRegion.Min > 0 の場合、サウンドは PlaybackRegion.Min の時間から再生し始めます。

  • PlaybackRegion.Min < 0 の場合、サウンドは 0 から再生し始めます。

  • PlaybackRegion.Max > Sound.TimeLength の場合、サウンドは Sound.TimeLength で停止します。

  • PlaybackRegion.Max < Sound.TimeLength の場合、サウンドはその時間に 正確に その時間に停止します。

  • PlaybackRegion.Min が PlaybackRegion.Max の場合、PlayBackRegion は非作動になります。

PlaybackRegionsEnabled

並列読み取り

true タグが付いている場合、このプロパティは、Sound アクセスを、Sound.PlaybackRegion および 1> Class.Sound.LoopRegion 1> プロパティに、より正確に制御できるようにします。

PlaybackSpeed

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

Class.Sound がプレイする速度を決定します。値が大きいほど、サウンドがより速く戻る生されます。

たとえば、2の値は Sound を 2x 速く再生させますが、0.5の値は Sound.TimeLength (in 秒) で完了します。PlaybackSpeed が 1 で等しいと、サウンドは 2>Class.Sound.TimeLength2> (in 秒) で完了します。

サウンドの PlaybackSpeed を上げると、それはより高いピッチで再生されるようになります。

コードサンプル

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

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

Class.Sound が現在プレイ中かどうかを示します。これは切り替え可能であり、このプロパティは常にレプリケートされます。

スタジオエディタでは、 Sounds は時間が停止されているため、プレイできません。編集モードで Sound.Playing を trueに設定しても、編集モードの外でプラグインからオーディオを再生することはできません。しかし、 Class

このプロパティは Sound.IsPlaying と混同してはなりません。プレイを有効にすると、サウンドの再生を開始または停止できます。

Play が false に設定されているときは、サウンドの Sound.TimePosition プロパティはリセットされません。これは、Sound:Play() が再び設定されたときに音が停止した時点から続行されるようになります。ただし、Class.Sound:Play() 機能を使用してサウンドの時間位置

コードサンプル

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

並列読み取り

クライアントのリスナーが Sound のオリジンから最大距離を保ち、Part または Attachment (3D サウンド) に親接されたサウンドのみを聞くことができます。これは、1>Class.Sound1> に親接されたサウンドのみに適用されます。

ロールオフマックス距離(サウンドが消えるまでの時間)が影響を与えるサウンドの隠れ方(サウンドが消えるまでの時間)は、Sound.RollOffMode プロパティによります。ロールオフモード

RollOffMode がリニアタイプの距離モデル (または LinearSquared など) に設定されると、サウンドは Sound.EmitterSize と MaxDistance の間で衰減します (プレイバックボリュームが 0 に達すると、リニア化がより直感的に処理されます)。これは、但し、より現実的な方法でサウンドを処理で

RollOffMinDistance

並列読み取り

3D Sound (直接の子供の Class.BasePart または Class.Attachment ) が始まる最小の距離 (ボリュームを減少する) で、弱まり始めます。

Class.BasePart または Attachment が親になっている Workspace は、クライアントのサウンドリスナーの位置 (デフォルトでは 1>Class.Camera

Class.Sound がロールオフモードにより後退する方法は、Class.Sound がロールオフミッションの距離を超えると、ロールオフモードにより後退します。

RollOffMode

並列読み取り

このプロパティは、3D Sounds がサウンドの親に対する距離を減少させる方法を設定します (サウンドを減衰させる)。この枚数は Enum.RollOffMode の枚数の 1つに設定できます。

次のコードは、RollOffMode を Linear に設定します:


sound.RollOffMode = Enum.RollOffMode.Linear

異なるモード

次のオプションが利用可能です:


<tbody>
<tr>
<td>逆</td>
<td>音量は、<code>サウンド/ロールオフミンディスタンス</code> の逆方向に減少します。</td>
</tr>
<tr>
<td>逆向きタッパー</td>
<td>ハイブリッドモデル。<code>RollOffMinDistance</code> と <code>Sound/RollOffMaxDistance</code> の両方に近いときに Inverse モデルをフォローし、RollOffMinDistance と 1> Sound/RollOffMaxDistance1> の両方に近いときに Linear Square モデルをフォローします。</td>
</tr>
<tr>
<td>直線</td>
<td>ボリュームは、<code>RollOffMinDistance</code> と <code>Sound/RollOffMaxDistance</code> の間のライニアルな関係で減少します。</td>
</tr>
<tr>
<td>正方形</td>
<td>ボリュームは、<code>RollOffMinDistance</code> と <code>Sound/RollOffMaxDistance</code> の間に減少し、直線的な正方形の関係で減少します。</td>
</tr>
</tbody>
モード説明

逆方向 vs 直線距離のアタテネーション

デフォルトのサウンドは、逆距離補正を使用して、サウンドが現実世界でどのように減衰するかをミラーします(ENUM.RollOffMode.Inverse)。逆距離補正の下で、サウンドは距離の親に対するロールオフ距

ロールオフ最大距離は、逆モデルでは影響を受けませんが、この距離に到達すると、サウンドが完全に切断されます。これは、低値で最大距離を使用する場合に特に急な場合です。

直線距離の減衰は、音がロールオフミニ距離からロールオフマックス距離に移動すると、サウンドが減衰し始めます。ロールオフミニ距離からロールオフマックス距離に移動すると、サウンドの減衰

SoundGroup

並列読み取り

この Sound にリンクされている SoundGroup.Volume は、1>Class.SoundGroup.Volume1> と 4>Class.SoundGroup.Volume4> に適用されると、サウンドグループに音が適用されます。サウンドは、1つのサウンドグループにのみ適用されることができます。

SoundGroups は、複数の Sounds を一度に管理するために使用されます。サウンドグループのプロパティを設定すると、Sound にサウンドが追加されます。

コードサンプル

This sample demonstrates how a SoundGroup can be used to change the volume of its associated Sounds and apply SoundEffects.

In this example a Sound is instanced in the Workspace and assigned to a new SoundGroup. The Sound is played and during playback the volume is changed via the SoundGroup and a SoundEffect is added.

SoundGroups

local SoundService = game:GetService("SoundService")
-- create a sound group
local soundGroup = Instance.new("SoundGroup")
soundGroup.Parent = SoundService
-- create a sound
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://9120386436"
sound.Looped = true
sound.PlaybackSpeed = 2
sound.SoundGroup = soundGroup
sound.Parent = workspace
-- play the sound
sound:Play()
task.wait(10)
-- change the volume
soundGroup.Volume = 0.1
task.wait(3)
-- return the volume
soundGroup.Volume = 0.5
task.wait(4)
-- add a sound effect
local reverb = Instance.new("ReverbSoundEffect")
reverb.Parent = soundGroup

SoundId

ContentId
並列読み取り

このプロパティは、Soundオブジェクトに関連するサウンドファイルのコンテンツIDです。サウンドが Robloxにアップロードされると、コンテンツID はアップロードされたサウンドの URL で見つけることができます。

URL はコンテンツ ID と同じではないことを覚えておくことは重要です。Roblox Studio の Sound プロパティに直接貼り付けると、Studio は自動的に修正しますが、Script から設定されている場合は、正しいコンテンツ ID が必要になります。たとえば:


"https://www.roblox.com/catalog/9120386436" -- ウェブ URL (機能しません)
"http://www.roblox.com/asset/?id=9120386436" -- コンテンツID (機能する)
"rbxassetid://9120386436" -- Content ID (alternative version, will work)

コードサンプル

This sample gives a simple example of how a Sound that is not parented to a Part or Attachment will play at a constant volume throughout the place. A sound is instanced and parented to the Workspace, and then played.

Sound in the Workspace

local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://9120386436"
sound.Looped = true
sound.Parent = workspace
sound:Play()

TimeLength

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

秒単位の Sound の長さ。Sound が読み込まれていない場合、この値は 0 になります。

このプロパティは、Sound.PlaybackSpeed と一緒に使用されることが多く、サウンドの速度を調整して、特定の期間 (例: サンプル) 持続させます。Sound.PlaybackSpeed が 1 で等しいと、サウンドは TimeLength 秒で完了します。

コードサンプル

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

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

Class.Sound の進行状況を秒単位で表示します。Sound のプレイバック位置を変更することができます。音がすでに再生されている場合は、再生は指定された位置にスナップされます。Class.Sound が次に再生されると、プレイバックは設定された位置に開始されます。

Class.Sound が再生されると、Sound.PlaybackSpeed が毎秒 Sound.TimeLength で増加します。1>Class.Sound.TimeLength1> が 4>Class.Sound.Time4> を設定している

TimePosition をループ中のトラックの長さより大きな値に設定すると、ラップアラウンドされなくなります。この動作を望む場合は、フォロー中のコードを実行する必要があります。

新しいPositionがサウンド.TimeLengthより大きい場合、新しいPosition = newPosition - sound.TimeLength 終了サウンド.Position = newPosition

現在、SetTimePosition をゼロ以下に設定すると、再生に影響しませんが、この動作は信頼しないでください。

コードサンプル

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

並列読み取り

Class.Sound のボリューム。デフォルトは 0 から 10 です。

Class.SoundGroup のメンバーである SoundGroup のプレイバックボリューム (但し、SoundGroup.Volume のプロパティではない) は、その 1>Class.SoundGroup1> のボ

コードサンプル

This sample includes a demonstration of how a Sound's volume can be set using the Sound.Volume property.

Sound Volume

local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://9120386436"
sound.Looped = true
sound.PlaybackSpeed = 2
sound.Parent = workspace
sound.Volume = 2
sound:Play()
task.wait(7)
sound.Volume = 0.2

方法

Pause

void

Class.Sound.Playing を偽に設定します。これは、サウンドが再生されている場合、Sound の再生を一時停止します。Sound:Stop() とは、サウンドが再生されている場合、1>Class.Sound.TimePosition1> をリセットしないこ

サウンド機能の異なる影響については、Sound.PlayingSound.TimePosition の下に示されています。


<tbody>
<tr>
<td>サウンド:Play()</td>
<td>True</td>
<td>Lua の最後の値 (デフォルト 0)</td>
</tr>
<tr>
<td>サウンド:Pause()</td>
<td>偽</td>
<td>-</td>
</tr>
<tr>
<td>サウンド:Resume()</td>
<td>True</td>
<td>-</td>
</tr>
<tr>
<td>サウンド:Stop()</td>
<td>偽</td>
<td>0</td>
</tr>
</tbody>
機能サウンド.プレイサウンド。タイムポジション

戻り値

void

コードサンプル

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

void

プレイする SoundSound.TimePosition を最後の Script (または 0 が設設定するされていない場合) に設定し、2>Class.Sound.Playing2> を true に設定します。

Class.Sound 機能の異なる影響については、Sound.PlayingSound.TimePosition の下に示されています。


<tbody>
<tr>
<td>サウンド:Play()</td>
<td>True</td>
<td>Lua の最後の値 (デフォルト 0)</td>
</tr>
<tr>
<td>サウンド:Pause()</td>
<td>偽</td>
<td>-</td>
</tr>
<tr>
<td>サウンド:Resume()</td>
<td>True</td>
<td>-</td>
</tr>
<tr>
<td>サウンド:Stop()</td>
<td>偽</td>
<td>0</td>
</tr>
</tbody>
機能サウンド.プレイサウンド。タイムポジション

戻り値

void

コードサンプル

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

void

Resumes the Sound . Sets Sound.Playing to true. Does not alter Sound.TimePosition and thus can be used to resume the playback of a sound stopped using 1> Class.Sound:Pause()1> .

サウンド機能の異なる影響については、Sound.PlayingSound.TimePosition の下に示されています。


<tbody>
<tr>
<td>サウンド:Play()</td>
<td>True</td>
<td>Lua の最後の値 (デフォルト 0)</td>
</tr>
<tr>
<td>サウンド:Pause()</td>
<td>偽</td>
<td>-</td>
</tr>
<tr>
<td>サウンド:Resume()</td>
<td>True</td>
<td>-</td>
</tr>
<tr>
<td>サウンド:Stop()</td>
<td>偽</td>
<td>0</td>
</tr>
</tbody>
機能サウンド.プレイサウンド。タイムポジション

戻り値

void

コードサンプル

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

void

Class.Sound を停止します。 Class.Sound.Playing を偽に設定し、 Class.Sound.TimePosition を0に設定します。

サウンド機能の異なる影響については、Sound.PlayingSound.TimePosition の下に示されています。


<tbody>
<tr>
<td>サウンド:Play()</td>
<td>True</td>
<td>Lua の最後の値 (デフォルト 0)</td>
</tr>
<tr>
<td>サウンド:Pause()</td>
<td>偽</td>
<td>-</td>
</tr>
<tr>
<td>サウンド:Resume()</td>
<td>True</td>
<td>-</td>
</tr>
<tr>
<td>サウンド:Stop()</td>
<td>偽</td>
<td>0</td>
</tr>
</tbody>
機能サウンド.プレイサウンド。タイムポジション

戻り値

void

コードサンプル

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

Class.Sound ループが発動するときに発動するイベント。音声 ID と数回ループされた回数を返し、それぞれコンテンツ ID とループ回数を返します。

Class.Sound が停止されると、ループされたカウンターのリセットが意味し、次の DidLoop イベントが数値を減算して 1 を返すことになります。

パラメータ

soundId: string

Class.Sound.SoundId の Sound がループしました。

numOfTimesLooped: number

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

Class.Sound がプレイを完了し、停止したときに発動します。このイベントは、Sound.Looped が設定されているときに再終了を続けると発動しません。

このイベントは、プレイバックが完了したときにサウンドを破壊するのに常に使用されます。


sound:Play()
sound.Ended:Wait()
sound:Destroy()

このイベントは、サウンドが終了わりに到達した場合にのみ発動します。これは、サウンドがプレイバックを完了する前に停止されることがないことを意味します。この使用には Sound.Stopped です。

パラメータ

soundId: string

終了した Class.Sound.SoundId の Class.Sound。


Loaded

Sound.Loaded イベントは、Sound が読み込まれるときに発動します。

このイベントは、サウンドが読み込まれるときにのみ発動します。これは、サウンドがすでに読み込まれているときに聞くと、返さないことを意味します。ですから、このイベントに接続する前に Sound.IsLoaded をチェックすることをお勧めします。

パラメータ

soundId: string

読み込まれた Sound.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

Class.Sound:Pause() を使用して、Sound:Pause() が休止されるときに発動します。

Class.Sound.Played 、Sound.Resumed 、および Sound.Stopped の場合、それぞれのサウンド機能により、イベントが発動します。これは、1>1>Class.Sound:Pause1> が呼び出されるときにのみ Pause が発動することを意味します。これは、4>Class

パラメータ

soundId: string

一時停止された Sound.SoundIdSound の Class.Sound です。


コードサンプル

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

Class.Sound:Play() 関数を使用している Sound:Play() が再生されるときにファイアを起動します。

Class.Sound.Stopped 、Sound.Paused および Sound.Resumed の場合、それぞれのサウンド機能により、イベントが発動します。これは、

パラメータ

soundId: string

再生された Class.Sound.SoundId の Class.Sound。


コードサンプル

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

Class.Sound:Resume() を使用して、Sound:Resume() が再開されるときにファイアを起動します。

Class.Sound.Played 、Sound.Paused および Sound.Stopped の場合、それぞれのサウンド機能により、イベントが発動します。これは、1> 1>Class.Sound:Resume()1> が呼び出されるときにのみ 4>Resume4> が発動することを意味します

パラメータ

soundId: string

Class.Sound.SoundId の Sound が再開されています。


コードサンプル

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

Class.Sound:Stop 機能により、Sound:Stop() が停止されると、ファイアが発生します。

Class.Sound.Played 、Sound.Paused および Sound.Resumed の場合、それぞれのサウンド機能により、イベントが発動します。これは、1> Class.Sound:Stop()1> が呼び出されるときにのみ停止することを意味します

パラメータ

soundId: string

停止した Sound.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