Motor Sınıfı
Sound
*Bu içerik, yapay zekâ (beta) kullanılarak çevrildi ve hatalar içerebilir. Sayfayı İngilizce görüntülemek için buraya tıkla.
Özet
Özellikler
SoundId:ContentId |
Olaylar
DidLoop(soundId: string,numOfTimesLooped: number):RBXScriptSignal |
Ended(soundId: string):RBXScriptSignal |
Loaded(soundId: string):RBXScriptSignal |
Paused(soundId: string):RBXScriptSignal |
Played(soundId: string):RBXScriptSignal |
Resumed(soundId: string):RBXScriptSignal |
Stopped(soundId: string):RBXScriptSignal |
Kod Örnekleri
Müzik Çalma Parçası
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
-- bir ses oluştur
local sound = Instance.new("Sound", part)
sound.SoundId = "rbxassetid://9120386436"
sound.EmitterSize = 5 -- yayıcı boyutunu azalt (daha erken hacim düşüşü için)
sound.Looped = true
sound.Parent = part
local clickDetector = Instance.new("ClickDetector")
clickDetector.Parent = part
-- sesi çalma / durdurma
clickDetector.MouseClick:Connect(function()
if not sound.IsPlaying then
part.BrickColor = BrickColor.new("Bright green")
sound:Play()
else
part.BrickColor = BrickColor.new("Bright red")
sound:Stop()
end
end)API Referansı
Özellikler
EmitterSize
IsLoaded
Kod Örnekleri
Ses Yükle
local sound = script.Parent.Sound
if not sound.IsLoaded then
sound.Loaded:Wait()
end
print("Ses yüklendi!")IsPaused
Kod Örnekleri
Ses Çalıyor ve Ses Duraklatıldı
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) -- doğru, yanlış
task.wait(2)
sound:Pause()
print(sound.IsPlaying, sound.IsPaused) -- yanlış, doğru
task.wait(2)
sound:Play()
print(sound.IsPlaying, sound.IsPaused) -- doğru, yanlış
task.wait(2)
sound:Stop()
print(sound.IsPlaying, sound.IsPaused) -- yanlış, doğruIsPlaying
Kod Örnekleri
Ses Çalıyor ve Ses Duraklatıldı
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) -- doğru, yanlış
task.wait(2)
sound:Pause()
print(sound.IsPlaying, sound.IsPaused) -- yanlış, doğru
task.wait(2)
sound:Play()
print(sound.IsPlaying, sound.IsPaused) -- doğru, yanlış
task.wait(2)
sound:Stop()
print(sound.IsPlaying, sound.IsPaused) -- yanlış, doğruisPlaying
Looped
Kod Örnekleri
Bir Sayıyı Yüksekten Tekrar Oynat
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
-- bağlantıyı kes
connection:Disconnect()
-- sesi durdur
sound:Stop()
end
end)
sound:Play()
end
end
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://0"
loopNTimes(sound, 5)MaxDistance
MinDistance
Pitch
PlaybackLoudness
Kod Örnekleri
Ses Amplitüd Çubuğu
-- StarterPlayer > StarterPlayerScripts içine yerleştirilecek
local Players = game:GetService("Players")
-- yerel oyuncu PlayerGui için bekle
local LocalPlayer = Players.LocalPlayer
local playerGui = LocalPlayer:WaitForChild("PlayerGui")
-- bir ScreenGui oluştur
local screenGui = Instance.new("ScreenGui")
screenGui.Parent = playerGui
-- çubuğumuz için bir tutucu oluştur
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
-- bir çubuk oluştur
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
-- bir ses oluştur
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://9120386436"
sound.Looped = true
sound.Parent = screenGui
sound:Play()
-- bir maksimum yüksek ses tanımla
local maxLoudness = 30
-- amplitüd çubuğunu animasyonla
while true do
local amplitude = math.clamp(sound.PlaybackLoudness / maxLoudness, 0, 1)
bar.Size = UDim2.new(amplitude, 0, 1, 0)
wait(0.05)
endPlaybackSpeed
Kod Örnekleri
Ses Oynatma Hızı
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://9120386436"
sound.Looped = true
sound.Parent = workspace
sound:Play()
task.wait(10)
sound.PlaybackSpeed = 3 -- 3 kat daha hızlı
task.wait(5)
sound.PlaybackSpeed = 0.5 -- 2 kat daha yavaş
task.wait(5)
sound.PlaybackSpeed = 1 -- varsayılanPlaying
Kod Örnekleri
Ses Çalma
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://9120386436"
sound.Looped = true
sound.Parent = workspace
print("ses çalıyor")
sound.Playing = true
task.wait(10)
print("ses durduruluyor")
sound.Playing = false
task.wait(5)
sound.Playing = true
local timePosition = sound.TimePosition
print("zaman pozisyonunda devam edildi: " .. tostring(timePosition)) -- c. 10 saniyeSoundId
Sound.SoundId:ContentId
TimeLength
Kod Örnekleri
Belirli Bir Süre İçin Ses Çal
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
Kod Örnekleri
Ses Zamanı Pozisyonu
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 = 0Yöntemler
Pause
Sound:Pause():()
Dönüşler
()
Kod Örnekleri
Ses Fonksiyonları
-- bir ses oluştur
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://9120386436"
if not sound.IsLoaded then
sound.Loaded:Wait()
end
-- olayları dinle
sound.Played:Connect(function(_soundId)
print("Sound.Played olayı")
end)
sound.Paused:Connect(function(_soundId)
print("Sound.Paused olayı")
end)
sound.Resumed:Connect(function(_soundId)
print("Sound.Resumed olayı")
end)
sound.Stopped:Connect(function(_soundId)
print("Sound.Stopped olayı")
end)
sound:Play()
print("çalıştır", sound.Playing, sound.TimePosition) -- çalıştır true 0
task.wait(10)
sound:Pause()
print("duraklat", sound.Playing, sound.TimePosition) -- duraklat false 10
task.wait(3)
sound:Resume()
print("çalıştır", sound.Playing, sound.TimePosition) -- çalıştır true 10
task.wait(3)
sound:Stop()
print("durdur", sound.Playing, sound.TimePosition) -- durdur false 0
task.wait(3)
sound:Play()
print("çalıştır", sound.Playing, sound.TimePosition) -- çalıştır true 0pause
Play
Sound:Play():()
Dönüşler
()
Kod Örnekleri
Ses Fonksiyonları
-- bir ses oluştur
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://9120386436"
if not sound.IsLoaded then
sound.Loaded:Wait()
end
-- olayları dinle
sound.Played:Connect(function(_soundId)
print("Sound.Played olayı")
end)
sound.Paused:Connect(function(_soundId)
print("Sound.Paused olayı")
end)
sound.Resumed:Connect(function(_soundId)
print("Sound.Resumed olayı")
end)
sound.Stopped:Connect(function(_soundId)
print("Sound.Stopped olayı")
end)
sound:Play()
print("çalıştır", sound.Playing, sound.TimePosition) -- çalıştır true 0
task.wait(10)
sound:Pause()
print("duraklat", sound.Playing, sound.TimePosition) -- duraklat false 10
task.wait(3)
sound:Resume()
print("çalıştır", sound.Playing, sound.TimePosition) -- çalıştır true 10
task.wait(3)
sound:Stop()
print("durdur", sound.Playing, sound.TimePosition) -- durdur false 0
task.wait(3)
sound:Play()
print("çalıştır", sound.Playing, sound.TimePosition) -- çalıştır true 0play
Resume
Sound:Resume():()
Dönüşler
()
Kod Örnekleri
Ses Fonksiyonları
-- bir ses oluştur
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://9120386436"
if not sound.IsLoaded then
sound.Loaded:Wait()
end
-- olayları dinle
sound.Played:Connect(function(_soundId)
print("Sound.Played olayı")
end)
sound.Paused:Connect(function(_soundId)
print("Sound.Paused olayı")
end)
sound.Resumed:Connect(function(_soundId)
print("Sound.Resumed olayı")
end)
sound.Stopped:Connect(function(_soundId)
print("Sound.Stopped olayı")
end)
sound:Play()
print("çalıştır", sound.Playing, sound.TimePosition) -- çalıştır true 0
task.wait(10)
sound:Pause()
print("duraklat", sound.Playing, sound.TimePosition) -- duraklat false 10
task.wait(3)
sound:Resume()
print("çalıştır", sound.Playing, sound.TimePosition) -- çalıştır true 10
task.wait(3)
sound:Stop()
print("durdur", sound.Playing, sound.TimePosition) -- durdur false 0
task.wait(3)
sound:Play()
print("çalıştır", sound.Playing, sound.TimePosition) -- çalıştır true 0Stop
Sound:Stop():()
Dönüşler
()
Kod Örnekleri
Ses Fonksiyonları
-- bir ses oluştur
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://9120386436"
if not sound.IsLoaded then
sound.Loaded:Wait()
end
-- olayları dinle
sound.Played:Connect(function(_soundId)
print("Sound.Played olayı")
end)
sound.Paused:Connect(function(_soundId)
print("Sound.Paused olayı")
end)
sound.Resumed:Connect(function(_soundId)
print("Sound.Resumed olayı")
end)
sound.Stopped:Connect(function(_soundId)
print("Sound.Stopped olayı")
end)
sound:Play()
print("çalıştır", sound.Playing, sound.TimePosition) -- çalıştır true 0
task.wait(10)
sound:Pause()
print("duraklat", sound.Playing, sound.TimePosition) -- duraklat false 10
task.wait(3)
sound:Resume()
print("çalıştır", sound.Playing, sound.TimePosition) -- çalıştır true 10
task.wait(3)
sound:Stop()
print("durdur", sound.Playing, sound.TimePosition) -- durdur false 0
task.wait(3)
sound:Play()
print("çalıştır", sound.Playing, sound.TimePosition) -- çalıştır true 0stop
Olaylar
DidLoop
Kod Örnekleri
Bir Sayıyı Yüksekten Tekrar Oynat
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
-- bağlantıyı kes
connection:Disconnect()
-- sesi durdur
sound:Stop()
end
end)
sound:Play()
end
end
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://0"
loopNTimes(sound, 5)Loaded
Parametreler
Kod Örnekleri
Ses Yükle
local sound = script.Parent.Sound
if not sound.IsLoaded then
sound.Loaded:Wait()
end
print("Ses yüklendi!")Paused
Parametreler
Kod Örnekleri
Ses Fonksiyonları
-- bir ses oluştur
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://9120386436"
if not sound.IsLoaded then
sound.Loaded:Wait()
end
-- olayları dinle
sound.Played:Connect(function(_soundId)
print("Sound.Played olayı")
end)
sound.Paused:Connect(function(_soundId)
print("Sound.Paused olayı")
end)
sound.Resumed:Connect(function(_soundId)
print("Sound.Resumed olayı")
end)
sound.Stopped:Connect(function(_soundId)
print("Sound.Stopped olayı")
end)
sound:Play()
print("çalıştır", sound.Playing, sound.TimePosition) -- çalıştır true 0
task.wait(10)
sound:Pause()
print("duraklat", sound.Playing, sound.TimePosition) -- duraklat false 10
task.wait(3)
sound:Resume()
print("çalıştır", sound.Playing, sound.TimePosition) -- çalıştır true 10
task.wait(3)
sound:Stop()
print("durdur", sound.Playing, sound.TimePosition) -- durdur false 0
task.wait(3)
sound:Play()
print("çalıştır", sound.Playing, sound.TimePosition) -- çalıştır true 0Played
Parametreler
Kod Örnekleri
Ses Fonksiyonları
-- bir ses oluştur
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://9120386436"
if not sound.IsLoaded then
sound.Loaded:Wait()
end
-- olayları dinle
sound.Played:Connect(function(_soundId)
print("Sound.Played olayı")
end)
sound.Paused:Connect(function(_soundId)
print("Sound.Paused olayı")
end)
sound.Resumed:Connect(function(_soundId)
print("Sound.Resumed olayı")
end)
sound.Stopped:Connect(function(_soundId)
print("Sound.Stopped olayı")
end)
sound:Play()
print("çalıştır", sound.Playing, sound.TimePosition) -- çalıştır true 0
task.wait(10)
sound:Pause()
print("duraklat", sound.Playing, sound.TimePosition) -- duraklat false 10
task.wait(3)
sound:Resume()
print("çalıştır", sound.Playing, sound.TimePosition) -- çalıştır true 10
task.wait(3)
sound:Stop()
print("durdur", sound.Playing, sound.TimePosition) -- durdur false 0
task.wait(3)
sound:Play()
print("çalıştır", sound.Playing, sound.TimePosition) -- çalıştır true 0Resumed
Parametreler
Kod Örnekleri
Ses Fonksiyonları
-- bir ses oluştur
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://9120386436"
if not sound.IsLoaded then
sound.Loaded:Wait()
end
-- olayları dinle
sound.Played:Connect(function(_soundId)
print("Sound.Played olayı")
end)
sound.Paused:Connect(function(_soundId)
print("Sound.Paused olayı")
end)
sound.Resumed:Connect(function(_soundId)
print("Sound.Resumed olayı")
end)
sound.Stopped:Connect(function(_soundId)
print("Sound.Stopped olayı")
end)
sound:Play()
print("çalıştır", sound.Playing, sound.TimePosition) -- çalıştır true 0
task.wait(10)
sound:Pause()
print("duraklat", sound.Playing, sound.TimePosition) -- duraklat false 10
task.wait(3)
sound:Resume()
print("çalıştır", sound.Playing, sound.TimePosition) -- çalıştır true 10
task.wait(3)
sound:Stop()
print("durdur", sound.Playing, sound.TimePosition) -- durdur false 0
task.wait(3)
sound:Play()
print("çalıştır", sound.Playing, sound.TimePosition) -- çalıştır true 0Stopped
Parametreler
Kod Örnekleri
Ses Fonksiyonları
-- bir ses oluştur
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://9120386436"
if not sound.IsLoaded then
sound.Loaded:Wait()
end
-- olayları dinle
sound.Played:Connect(function(_soundId)
print("Sound.Played olayı")
end)
sound.Paused:Connect(function(_soundId)
print("Sound.Paused olayı")
end)
sound.Resumed:Connect(function(_soundId)
print("Sound.Resumed olayı")
end)
sound.Stopped:Connect(function(_soundId)
print("Sound.Stopped olayı")
end)
sound:Play()
print("çalıştır", sound.Playing, sound.TimePosition) -- çalıştır true 0
task.wait(10)
sound:Pause()
print("duraklat", sound.Playing, sound.TimePosition) -- duraklat false 10
task.wait(3)
sound:Resume()
print("çalıştır", sound.Playing, sound.TimePosition) -- çalıştır true 10
task.wait(3)
sound:Stop()
print("durdur", sound.Playing, sound.TimePosition) -- durdur false 0
task.wait(3)
sound:Play()
print("çalıştır", sound.Playing, sound.TimePosition) -- çalıştır true 0