Sound

Artık kullanılmayanları göster

*Bu içerik, yapay zekâ (beta) kullanılarak çevrildi ve hatalar içerebilir. Sayfayı İngilizce görüntülemek için buraya tıkla.

Sound ses çıkaran bir nesnedir.Bir BasePart veya Attachment içine yerleştirildiğinde, bu nesne sesini o parçanın BasePart.Position veya ekipmanın Attachment.WorldPosition kısmından yayacaktır.Bu yerleşimde, bir Sound Doppler etkisini sergiler, yani frekansı ve yüksekliği, bağlı olduğu herhangi bir ekipman veya parçaya göre değişir.Ayrıca, ses dinleyicisinin (varsayılan olarak Camera konumu) ve sesin ebeveyninin konumuyla arasındaki mesafe tarafından sesin hacmi belirlenecektir.Daha fazla bilgi için bakın RollOffMode .

Bir ses "küresel" olarak kabul edilir if it is değil bir BasePart veya bir Attachment ebeveynli değilse.Bu durumda, ses tüm dünyaaynı seviyede çalacaktır.

Kod Örnekleri

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)

Özet

Özellikler

Yöntemler

Etkinlikler

Özellikler

ChannelCount

Salt Okunur
Çoğaltılmamış
Gezilemez
Roblox Betik Güvenliği
Paralel oku

IsLoaded

Salt Okunur
Çoğaltılmamış
Paralel oku

Bu özellik, Sound Roblox sunucularından yüklendiğinde ve oynanmaya hazır olduğunda true dir.Bu özellik ve Loaded etkinliğini kullanarak bir sesin oynanmadan önce yüklendiğini doğrulayabilirsiniz.

Kod Örnekleri

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

Gizli
Salt Okunur
Çoğaltılmamış
Paralel oku

Bu okuma-sadece özelliği, Sound oynanmıyor olduğunda true döndürür.Bir ses, kullanarak duraklatılmışsa, duraklatılmışsa veya ses asla çalınmadıysa kullanarak geri dönebileceğini unutmayın.

As IsPaused okuma sadece yazılabilir olduğundan, sesi durdurmak için kullanılamaz; Stop() veya Pause() yerine kullanılmalı.

Kod Örnekleri

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

Gizli
Salt Okunur
Çoğaltılmamış
Paralel oku

Bu okuma sadece özellik, Sound oynarken gerçek döndürür.

As IsPlaying okuma sadece yazılabilir olduğundan, ses çalmak için kullanılamaz; Play() yerine kullanılmalı.

Kod Örnekleri

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

Paralel oku

Bir dizi, PlaybackRegion içinde istenen döngü başlangıcını ve döngü sonunu belirten, saniyeler içinde.

  • Eğer Class.Sound.LoopRegion|LoopRegion.Min``>``Class.Sound.PlaybackRegion|PlaybackRegion.Min , döngü LoopRegion.Min 'dan başlar.

  • Eğer Class.Sound.LoopRegion|LoopRegion.Min``<``Class.Sound.PlaybackRegion|PlaybackRegion.Min , döngü PlaybackRegion.Min 'dan başlar.

  • Eğer Class.Sound.LoopRegion|LoopRegion.Max``>``Class.Sound.PlaybackRegion|PlaybackRegion.Max , döngü PlaybackRegion.Max 'de başlar.

  • Eğer Class.Sound.LoopRegion|LoopRegion.Max``<``Class.Sound.PlaybackRegion|PlaybackRegion.Max , döngü o anda kesinlikle başlar.

  • Eğer Class.Sound.LoopRegion|LoopRegion.Min``==``Class.Sound.LoopRegion|LoopRegion.Max , Sound yerine özellik PlaybackRegion kullanır.

Looped

Paralel oku

Bu, Sound oynadıktan sonra tekrar edip etmediğini belirler.Döngülenen sesler, müzik ve arka plan ambiyans sesleri dahil olmak üzere çeşitli uygulamalar için uygundur.

DidLoop etkinliği, sesin döngüye girdiği sayıyı izlemek için kullanılabilir.

Kod Örnekleri

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

Paralel oku

When true , Sound deneyimden kaldırıldığında oynatılacak, Sound ya da ataları nil olduğunda bir tane eklendiğinde.Bu, aşağıdakilerin tümü sesin çalmasına neden olacaktır, olduğunda:

  • sound:Destroy()
  • sound.Parent = nil
  • sound.Parent.Parent = nil

PlaybackLoudness

Salt Okunur
Çoğaltılmamış
Paralel oku

0 ve 1000 arasında bir sayı, çalınan Sound ne kadar yüksek olduğunu gösteriyor.Bu özellik, okunan sürede sesin oynatılma sıklığını yansıtır. This property reflects the amplitude of the sound's playback in the instance of time it is read.

Kod Örnekleri

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

Paralel oku

Bir TimeLength içinde arzu edilen başlangıç ve bitiş süresini belirten bir menzil, saniyeler içinde.

PlaybackRegionsEnabled

Paralel oku

Eğer true , bu özellik Sound oynatma denetimini daha doğru bir şekilde kontrol edebilecek PlaybackRegion ve LoopRegion özelliklere erişmenizi sağlar, ki bunlar oynatmayı daha doğru bir şekilde kontrol edebilir.

PlaybackSpeed

Çoğaltılmamış
Paralel oku

Bir Sound'nin oynayacağı hızı belirler, daha yüksek değerler sesin daha hızlı ve daha yüksek bir tonla oynayacağını sağlar.

Kod Örnekleri

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

Çoğaltılmamış
Paralel oku

Sound şu anda oynuyor mu gösterir. Bu değiştirilebilir ve bu özellik daima yeniden üretilebilir.

Studio'nun Özellikleri penceresinde, Düzenle modunda, Playing ile true geçiş yaparken, ses çalmaya başlamaz, ancak ses çalışma sırasında başlayacaktır.

Bu özellik okuma sadece özellik olan IsPlaying ile karıştırılmamalıdır.

Not that when Playing is set to false , the TimePosition property of the sound will not reset, meaning that when Playing is set to true again, the audio will continue from the time position it was when it was stopped.Ancak, Play() fonksiyonu sesi yeniden başlatmak için kullanılırsa, saat pozisyonu 0 'a sıfırlanacaktır.

Kod Örnekleri

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

Paralel oku

Maksimum mesafe, milimetrede, bir müşterinin dinleyicisi sesin kaynağından olabilir ve hala duyabilir.Sadece Sounds ebeveynli bir BasePart veya Attachment 'a uygulanır.

Bir sesin azalmasını nasıl RollOffMaxDistance etkiler (solgunun çıkış şekli) RollOffMode özelliğine bağlıdır.

RollOffMinDistance

Paralel oku

Bir ebeveynin bir Sound veya BasePart veya Attachment ile bağlantı kurduğu minimum mesafe, çivilerle, bir veya azalmaya başlayacak (hacim azaltma).

Bir sesin azalmasını nasıl RollOffMinDistance etkiler (solgunun çıkış şekli) RollOffMode özelliğine bağlıdır.

RollOffMode

Paralel oku

Bu özellik, bir Sound 'nin ebeveyn olduğu BasePart veya Attachment 'nin azaldığı mesafe olarak bir ses düşüklüğünün nasıl kontrol edileceğini kontrol eder, dinleyici ve ebeveyn arasındaki değişen mesafe.

Farklı modların ayrıntıları için, bakın Enum.RollOffMode .

SoundGroup

Paralel oku

Bu SoundGroup 'ye bağlı olan Sound.

SoundId

ContentId
Paralel oku

Bu özellik, Sound ile ilişkilendirilecek ses dosyasının içerik kimliğidir. Daha fazla bilgi için Ses Varlıklarına Bakın .

TimeLength

Salt Okunur
Çoğaltılmamış
Paralel oku

Saniyeler içinde Sound uzunluğu. Eğer Sound yüklenmiyorsa, bu değer 0 olacaktır.

Bu özellik genellikle bir sesin hızını ayarlamak için PlaybackSpeed ile birlikte kullanılır, böylece belirli bir süre boyunca sürer.

Kod Örnekleri

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

Çoğaltılmamış
Paralel oku

Bu özellik, Sound saniyeler içindeki ilerlemeyi yansıtır.Sesin oynatma konumunu önce ve oynatma sırasında değiştirmek için değiştirilebilir.

Bir Sound oynandığında, TimePosition saniye başına PlaybackSpeed oranında artar.Bir kez ulaştığında, ses olmadığı sürece duracaktır.

Bir döngü içindeki uzunluğdan daha büyük bir değere ayarlandığını unutmayın TimePosition çünkü bunun etrafında sarılmasına neden olmayacak.Bu davranış isteniyorsa, aşağıdaki kod parçacığını düşünün:


local newPosition = 1.5
if newPosition >= sound.TimeLength then
newPosition = newPosition - sound.TimeLength
end
sound.TimePosition = newPosition

Kod Örnekleri

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

Paralel oku

Sound 'nin hacmi. 0 ve 10 arasında ayarlanabilir ve varsayılan değeri 0.5 dir.

Eğer Sound bir SoundGroup üyesi ise, oynatma sesi (ancak onun Volume özelliği değil) grupSoundGroup.Volume özelliğinden etkilenir.

Yöntemler

Pause

()

Bu yöntem, oynatılıyorsa Sound oynatmayı durdurur ve Playing 'i false olarak ayarlar.Stop() 'den farklı olarak, TimePosition sıfırlanmıyor, yani ses Resume() kullanılarak yeniden başlatılabiliyor.


Dönüşler

()

Kod Örnekleri

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

()

Bu yöntem oynar ve bir senaryo tarafından ayarlanan son değere ayarlar ve ardından 'e ayarlar.


Dönüşler

()

Kod Örnekleri

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

()

Bu yöntem yeniden başlatır Sound ve Playing 'i true 'a ayarlar.TimePosition değiştirmez ve bu nedenle Pause() tarafından duraklatılan bir sesin oynatılmasına devam etmek için kullanılabilir.


Dönüşler

()

Kod Örnekleri

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

()

Bu yöntem durdurur ve için ayarlanır, sonra için ayarlanır.


Dönüşler

()

Kod Örnekleri

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

Etkinlikler

DidLoop

Herhangi bir Sound döngüsü herhangi bir zamanda ateş eder.Geri döndürür soundId ve numOfTimesLooped , sesin içerik kimliğini ve birbirine döngü sayısını vererek.

durdurulduğunda döngü sayacı sıfırlanır ve bir sonraki etkinliğinin geri döneceği anlamına gelir .

Parametreler

soundId: string

Döngü yapan SoundId ın Sound 'si.

numOfTimesLooped: number

Sound 'nin döndüğü sayı kez.


Kod Örnekleri

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

Oynatma tamamlandığında ve durduğunda Sound ateş eder. Bu olay genellikle oynatmayı bitirdiğinde bir sesi yok etmek için kullanılır:


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

Bu etkinin sesler için ateş etmeyeceğini unutmayın, çünkü bitirulaştıklarında oynatmaya devam ediyorlar.Bu etkinlik ayrıca çalma bitmeden önce ses durdurulduğunda da ateş etmeyecek; bunun için etkinliğini kullanın.

Parametreler

soundId: string

Bitmiş olan SoundId ın Sound 'sine.


Loaded

Sound yüklendiğinde ateş eder.

Bu olay yalnızca ses yüklendiğinde ateş olduğundan, bu olaya bağlanmadan önce sesin IsLoaded özelliklerini kontrol etmek önerilir.

Parametreler

soundId: string

Yüklenen SoundId 'nin Sound 'si.


Kod Örnekleri

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

Sound kullanarak duraklatıldığında herhangi bir zamanda yangınlar çıkar Pause().

Parametreler

soundId: string

Duraklatılan SoundId ın Sound 'si.


Kod Örnekleri

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

Herhangi bir Sound oynanırken Play() kullanılarak herhangi bir sırada ateş eder.Bu olay, çalınmadığı takdirde ateş etmeyecektir, çünkü ile ayarlanmış ve ses yok edilmiştir.

Parametreler

soundId: string

Oynanan SoundId ın Sound 'si.


Kod Örnekleri

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 kullanarak yeniden başlatıldığında ateş eder Resume().

Parametreler

soundId: string

The SoundId of the Sound being resumed. kaldırılıyor.


Kod Örnekleri

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

ile durdurulduğunda ateş eder, çalarken bir sesi yok ederek bu olayın ateşlenmesine neden olmaz.

Parametreler

soundId: string

Duran SoundId ın Sound ı.


Kod Örnekleri

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