Sound

แสดงที่เลิกใช้งานแล้ว

*เนื้อหานี้แปลโดยใช้ AI (เวอร์ชัน Beta) และอาจมีข้อผิดพลาด หากต้องการดูหน้านี้เป็นภาษาอังกฤษ ให้คลิกที่นี่

A Sound เป็นวัตถุที่ปล่อยเสียง

เสียง 2D และ 3D

เสียงที่วางอยู่ใน BasePart หรือ Attachment จะป

เสียงถูกพิจารณาว่าเป็น "ระดับโลก" หากไม่ได้เป็นลูกของ 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 และพร้อมที่จะเล่น

  • ซ่อนอยู่
    อ่านอย่างเดียว
    ไม่ซ้ำ
    อ่านพร้อมๆ กัน

    คุณสมบัตินี้จะกลับมาเป็นจริงเมื่อ Sound ไม่ได้เล่น

  • ซ่อนอยู่
    อ่านอย่างเดียว
    ไม่ซ้ำ
    อ่านพร้อมๆ กัน

    คุณสมบัตินี้จะกลับมาเป็นจริงเมื่อ Sound กำลังเล่น

  • อ่านพร้อมๆ กัน

    ระยะที่แสดงถึงต้นทางเริ่มต้นและต้นทางสิ้นสุดภายใน Sound.PlaybackRegion ในวินาที

  • อ่านพร้อมๆ กัน

    นี่กำหนดว่าจะให้ Sound ที่ซ้ำซากเมื่อมันเสร็จสิ้นเมื่อมันเล่น

  • อ่านพร้อมๆ กัน

    เมื่อใช่จะเล่น Sound เมื่อถูกนำออกจากเกมโดยการรวมพ่อค้าของ Sound หรือหนึ่งหากมีกำเนิดมาจาก nil

  • อ่านอย่างเดียว
    ไม่ซ้ำ
    อ่านพร้อมๆ กัน

    ตัวเลขระหว่าง 0 และ 1000 กำลังแสดงถึงความดังของ Sound ในขณะนี้

  • อ่านพร้อมๆ กัน

    ระยะที่ระบุเวลาเริ่มต้น (ต่ำสุด) และหยุด (สูงสุด) ภายใน Sound.TimeLength ในวินาที

  • อ่านพร้อมๆ กัน

    หาก จริง โปรไฟล์นี้ให้การเข้าถึง Sound ของคุณ กับ Sound.PlaybackRegion และ 2> Class.Sound.LoopRegion2> โปรไฟล์ ซึ่งสามารถควบคุมการเล่นได้มากขึ้น

  • ไม่ซ้ำ
    อ่านพร้อมๆ กัน

    กำหนดความเร็วที่ Sound จะเล่นด้วยค่าที่สูงขึ้นส่งผลให้เสียงเล่นเร็วขึ้นและด้วยความสูงขึ้น

  • ไม่ซ้ำ
    อ่านพร้อมๆ กัน

    ระบุว่า Sound กำลังเล่นอยู่ในขณะนี้หรือไม่

  • อ่านพร้อมๆ กัน

    ระยะทางสูงสุดในสตั๊ดส์, ผู้ฟังของลูกค้าสามารถมาจาก Sound\s ต้นแบบและยังได้ยินมัน ใช้ได้กับเสียงที่มีความสัมพันธ์กับ Part หรือ Attachment (เส

  • อ่านพร้อมๆ กัน

    ระยะระยะอ่อนสุดที่ต้องการสำหรับ 3D Sound (ลูกชายที่แท้จริงของ Class.BasePart หรือ Class.Attachment) จะเริ่มลดลง (ลดลงในปริมาณ)

  • อ่านพร้อมๆ กัน

    ควบคุมวิธีการที่ความดังของ 3D Sound (พร้อมอยู่ในระดับของ BasePart หรือ Attachment ) ปฏิสัมพันธ์กับความไกลระหว่างผู้ฟังและความดังของเสียงของพ่อค้า

  • อ่านพร้อมๆ กัน

    Class.SoundGroup ที่เกี่ยวข้องกับเสียงนี้ Sound จะผ่านไปยังเสียง เสียงและเอฟเฟ็กต์เสียงที่ประยุกต์ใช้กับเสียงนี้จะถูกนำไปใช้กับเสียง เสียงเท่านั้นในแต่ละกลุ่มเสียง

  • SoundId:ContentId
    อ่านพร้อมๆ กัน

    รายการนี้คือรหัสเนื้อหาของไฟล์เสียงที่เกี่ยวข้อง Sound อุปกรณ์ เมื่อเสียงถูกอัปโหลดไปยัง Roblox รหัสเนื้อหาสามารถพบได้ใน URL ของเสียงที่อัปโหลด

  • อ่านอย่างเดียว
    ไม่ซ้ำ
    อ่านพร้อมๆ กัน

    ความยาวของ Sound ในวินาที หาก Sound ไม่โหลด ค่านี้จะเป็น 0

  • ไม่ซ้ำ
    อ่านพร้อมๆ กัน

    แสดงความคืบหน้าในวินาทีของ Sound สามารถเปลี่ยนแปลงเพื่อเคลื่อนย้ายตำแหน่งการเล่นของ Sound ได้ทั้งก่อนและระหว่างการเล่น

  • อ่านพร้อมๆ กัน

    ระดับเสียงของ Sound สามารถปรับได้ระหว่าง 0 และ 10 ปกติจะตั้งค่าไว้ที่ 0.5 หมายเลข

วิธีการ

  • Pause():void

    ตั้งค่า Sound.Playing ให้เป็น false นี่จะหยุดการเล่นของ Sound หากเสียงกำลังเล่น เป็น Sound.TimePosition ไม่ได้รีเซ็ต เมื่อ 1> Class.Sound1> ได้ร

  • Play():void

    เล่น Sound ตั้งค่า Sound.TimePosition ไปยังค่าสุดท้ายที่ติดตั้งโดย Script (หรือ 0 หากยังไม่ได้ติดตั้ง) แล้วตั้งค่า 1> Class.Sound.Playing1> เป็น true

  • Resume():void

    รวบรวม Sound รีเซ็ต Sound.Playing ให้เป็นจริง ไม่เปลี่ยนแปลง Sound.TimePosition และดังนั้นจึงสามารถใช้เพื่อรีเซ็นการเล่นเสียงที่หยุดโดยการใช้

  • Stop():void

    หยุด Sound ตั้งค่า Sound.Playing เป็น false แล้วตั้งค่า Sound.TimePosition เป็น 0

อีเวนต์

คุณสมบัติ

ChannelCount

อ่านอย่างเดียว
ไม่ซ้ำ
ไม่สามารถเรียกดู
การรักษาความปลอดภัยของสคริปต์ Roblox
อ่านพร้อมๆ กัน

IsLoaded

อ่านอย่างเดียว
ไม่ซ้ำ
อ่านพร้อมๆ กัน

สมบัตินี้จะเป็นจริงเมื่อ Sound ได้โหลดจากเซิร์ฟเวอร์ Roblox และพร้อมที่จะเล่น

ใน 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 ไม่ได้เล่น หมายเหตุว่าสมบัติสมุดนี้จะไม่เป็นจริงเมื่อเสียงถูกหยุดใช้งานโดยใช้การใช้งาน Sound:Pause()

คุณสมบัตินี้จะเป็นจริงเฉพาะเมื่อ 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 กำลังเล่น

คุณสมบัตินี้สามารถเป็นจริงได้เมื่อ 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 ในเวลาวินาที

  • หาก LoopRegion.Min > PlaybackRegion.Min วงจรเริ่มต้นจาก LoopRegion.Min

  • หาก LoopRegion.Min < PlaybackRegion.Min , วงจรจะเริ่มตั้งแต่ PlaybackRegion.Min

  • หาก LoopRegion.Max > PlaybackRegion.Max โครงร่างจะเริ่มต้นที่ PlaybackRegion.Max

  • หาก LoopRegion.Max < PlaybackRegion.Max วงจรจะเริ่มต้นที่ ใช่เวลานั้น

  • หาก LoopRegion.Min เป็น LoopRegion.Max สิ่งนี้จะใช้ Sound แทน

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

อ่านพร้อมๆ กัน

เมื่อใช่, Sound จะเล่นเมื่อถูกนำออกจากเกม

หมายเหตุว่าเสียงจะเล่นเมื่อค่า Instance.Parent หรือหนึ่งในบรรพบุรุษของ Sound ตั้งค่าไว้เป็นศูนย์ นี่หมายถึงทั้งหมดของสิ่งต่อไปนี้จะทำให้เสี

เสียง: ทำลายเสียง.พ่อ = ไม่มีเสียงพ่อ.พ่อ = ไม่มีเสียงพ่อ

ตัวอย่างโค้ด

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 ในขณะนี้

อ่านแล้วดังนั้นสำหรับเสียงส่วนใหญ่จะปรับแก้อยู่เสมอ เนื่องจากสิ่งนี้จึงสามารถปรากฏในหน้า

ตัวอย่างโค้ด

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

อ่านพร้อมๆ กัน

ระยะที่ระบุเวลาเริ่มต้น (ต่ำสุด) และหยุด (สูงสุด) ภายใน Sound.TimeLength ในวินาที

  • หาก PlaybackRegion.Min > 0, เสียงจะเริ่มเล่นจากเวลา PlaybackRegion.Min

  • หาก PlaybackRegion.Min < 0 เสียงจะเริ่มเล่นจาก 0

  • หาก PlaybackRegion.Max > Sound.TimeLength เสียงจะหยุดที่ Sound.TimeLength

  • หาก PlaybackRegion.Max < Sound.TimeLength จะหยุดเสียงที่ ถูกต้อง ในเวลานั้น

  • หาก PlaybackRegion.Min <> PlaybackRegion.Max ไม่ได้ใช้งานอยู่

PlaybackRegionsEnabled

อ่านพร้อมๆ กัน

หาก จริง โปรไฟล์นี้ให้การเข้าถึง Sound ของคุณ กับ Sound.PlaybackRegion และ 2> Class.Sound.LoopRegion2> โปรไฟล์ ซึ่งสามารถควบคุมการเล่นได้มากขึ้น

PlaybackSpeed

ไม่ซ้ำ
อ่านพร้อมๆ กัน

กำหนดความเร็วที่ Sound จะเล่น ยิ่งมีค่ามากเท่าไหร่ ย้อนกลับ

เช่น มูลค่า 2 จะทำให้ Sound เล่นเร็วขึ้นสองเท่า ในขณะที่มูลค่า 0.5 จะทำให้เสียงใช้เวลา Sound.TimeLength (ในวินาที) เพื่อเสร็จสิ้น

หมายเหตุว่าเพิ่มความเร็วในการเล่นของเสียงจะทำให้เล่นที่ความถี่สูง

ตัวอย่างโค้ด

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 กำลังเล่นอยู่หรือไม่ สิ่งนี้สามารถเปิด/ปิดได้ และค่านี้จะเคลื่อนที่ตลอดไป

ในเวทีเอเชียนั้น Sounds ไม่สามารถเล่นได้เนื่องจากเวลาถูกหยุด การตั้งค่า Sound.Playing ให้เป็น true ในโหมดแก้ไขไม่ได้ทำ

คุณสมบัตินี้ไม่ควรสับสนกับ Sound.IsPlaying ซึ่งเป็นคุณสมบัติที่อ่านเท่านั้น การเล่นสามารถตั้งค่าไปยัง true หรือ false เพื่อเริ่มหรือหยุดการเล่นเสียง

หมายเหตุว่าเมื่อการเล่นถูกตั้งค่าเป็น false คุณสมบัติของเสียง Sound.TimePosition จะไม่รีเซ็ต ซึ่งหมายความว่าเมื่อการเล่นถูกตั้งค่าเป็น true อีกครั้ง

ตัวอย่างโค้ด

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)

วิธีการที่ RollOffMaxDistance ส่งผลต่อความเปลือยของเสียง (วิธีที่มันจะจางลง) ขึ้นอยู่กับคุณสมบัติ Sound.RollOffMode

เมื่อ RollOffMode ติดตั้งไว้ที่โมเดลระยะทางชนิดเส้นเส้น (Linear or LinearSquared) จะมีเสียงลดลงระหว่าง Sound.EmitterSize และ MaxDistance (ด้วยปริมาณการเล่นที่ถึงขีดจำกัดที่ RollOffMaxDistance) นี่เป็นเรื่

RollOffMinDistance

อ่านพร้อมๆ กัน

ระยะระยะอ่อนสุดที่ต้องการสำหรับ 3D Sound (ลูกชายที่แท้จริงของ Class.BasePart หรือ Class.Attachment) จะเริ่มลดลง (ลดลงในปริมาณ)

เสียงที่เกี่ยวข้องกับ BasePart หรือ Attachment ที่เป็นลูกหลานของ Workspace จะถ

วิธีที่ Sound จะลดลง (หายไป) หลังจากระยะเวลาระหว่างผู้ฟังและเสียงเกินขีดจำกัดที่กำหนดโดย RollOffMinDistance โดย RollOffMode

RollOffMode

อ่านพร้อมๆ กัน

สมบัตินี้กำหนดวิธีการที่ 3D Sounds ลดลง (หายไป) เมื่อระยะระหว่างผู้ฟังและพ่อของเสียงเพิ่มขึ้น สมบัตินี้สามารถตั้งค่าได้เป็นหนึ่งในค่าของ Enum.RollOffMode เม

ต่อไปนี้จะตั้งค่า RollOffMode เป็น Linear:


sound.RollOffMode = Enum.RollOffMode.Linear

โหมดที่แตกต่างกัน

ตัวเลือกต่อไปนี้สามารถใช้ได้:


<tbody>
<tr>
<td>ย้อนกลับ</td>
<td>ระดับเสียงลดลงจาก <code>Sound/RollOffMinDistance</code> ในวิธีที่เป็นบวก</td>
</tr>
<tr>
<td>InverseTapered และ</td>
<td>รุ่นไฮบริด ติดตามแนวโน้มแบบกลับขวาเมื่อใกล้ <code>รอลเอาท์มินเดอร์ดิสทรัคท์</code> และแนวโน้มแบบเส้นสายเมื่อใกล้ <code>โซน/รอลเอาท์แม็กซ์ดิสทรัคท์</code></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>
โหมดคำอธิบาย

การปรับปรุงค่าความเห็นทางไปยัง Inverse vs Linear Distance Attenuation

โดยปกติเสียงจะตั้งค่าให้ใช้การลดความจริงของเสียง (Enum.RollOffMode.Inverse) ซึ่งสะท้อนวิธีที่เสียงจะลดในโลกแห่งควา

RollOffMaxDistance จะไม่ส่งผลกระทบต่อการปรับแต่งภายใต้แนวคิดเชิงกลับกัน แต่จะทำให้เสียงหยุดสมบูรณ์เมื่อระยะนี้ถึง สิ่งนี้อาจเป็นเรื่องที่น่าประหลาดใจเมื่อใช้ค่าต่ำสุดสำหรับระยะสูงสุด

ระยะทางที่เป็นเส้นทางที่เป็นเส้นทางเชิงเส้น ระยะทางที่เป็นเส้นทางเชิงเส้นจะทำงานได้อย่างแตกต่างกัน ในร

SoundGroup

อ่านพร้อมๆ กัน

Class.SoundGroup ที่เกี่ยวข้องกับ Sound นี้ SoundGroup.Volume และ 1>Class.SoundGroup.Effects1> ที่ใช้กับเสียงกลุ่มนี้จะผ่านไปยังเสียง เสียงสามารถอยู่ในกลุ่มเสียง

SoundGroups ใช้เพื่อจัดการปริมาณและเอฟเฟ็กต์ของ Sounds หลายรายการในครั้งเดียว สิ่งหนึ่ง Sound ได้รับการเพิ่มในสิ่งที่เป็น 0>

ตัวอย่างโค้ด

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 อุปกรณ์ เมื่อเสียงถูกอัปโหลดไปยัง Roblox รหัสเนื้อหาสามารถพบได้ใน URL ของเสียงที่อัปโหลด

มีความสำคัญที่จะจำ URL ไม่ใช่เหมือนรหัสเนื้อหา มันจะทำงานเมื่อวางโดยตรงในโครงสร้าง SoundId ของ Sound ใน Roblox Studio เนื่องจาก Studio จะอัปเดตอัตโนมัติ


"https://www.roblox.com/catalog/9120386436" -- ที่อยู่ URL ของเว็บไซต์ (จะไม่ทำงาน)
"http://www.roblox.com/asset/?id=9120386436" -- รหัสเนื้อหา (จะทำงาน)
"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 เสียงจะใช้เวลาในการเสร็

ตัวอย่างโค้ด

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 สามารถเปลี่ยนแปลงเพื่อเปลี่ยนตำแหน่งการเล่นของเสียง หากเสียงกำลังเล่นอยู่แล้วก็จะสแน็ปไปที่ตำแหน่งที่กำหนด หา

เมื่อ Sound เปิดใช้งานได้เป็นเวลานาที Sound.PlaybackSpeed จะเพิ่มขึ้นในอัตรา Sound.TimeLength ต่อวินาที เม

หมายเหตุว่าการตั้งค่า TimePosition ให้เป็นค่ามากกว่าความยาวในแทร็กที่เป็นลูปจะไม่ทำให้มันหุ้มรอบ

หาก newPosition ใหญ่กว่า sound.TimeLength เสียงใหม่จะเป็นเสียงสิ้นสุดของเสียง.TimePosition = newPosition

การตั้งตำแหน่งเวลาให้เป็นค่าน้อยกว่า zero ในขณะนี้ไม่ส่งผลต่อการเล่น แต่พฤติกรรมนี้ไม่ควรเชื่อถือได้

ตัวอย่างโค้ด

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 สามารถตั้งได้ระหว่าง 0 และ 10 ตั้งค่าเริ่มต้นได้ที่ 0.5

หมุดหมายเหตุว่าหาก Sound เป็นสมาชิกของ SoundGroup จะมีปริมาณการเล่นของมัน (แต่ไม่ใช่ค่า Volume

ตัวอย่างโค้ด

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

ตั้ง Sound.Playing เป็น false สิ่งนี้ระงับการเล่นของ Sound หากเสียงกำลังเล่น ไม่เหมือน Sound:Stop() มันไม่รีเซ็ต 1>

ผลกระทบของเสียงที่แตกต่างกันใน Sound.Playing และ Sound.TimePosition จะปรากฏด้านล่าง


<tbody>
<tr>
<td>เสียง:เล่น()</td>
<td>ใช่</td>
<td>ค่าสุดท้ายที่ติดตั้งใน Lua (ค่าเริ่มต้น 0)</td>
</tr>
<tr>
<td>เสียง:Pause()</td>
<td>ปลอม</td>
<td>:-</td>
</tr>
<tr>
<td>เสียง: กลับเข้ามา()</td>
<td>ใช่</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

เล่น Sound ตั้งค่า Sound.TimePosition ไปยังค่าสุดท้ายที่ติดตั้งโดย Script (หรือ 0 หากยังไม่ได้ติดตั้ง) แล้วตั้งค่า 1> Class.Sound.Playing1> เป็น true

ผลกระทบของคุณสมบัติต่างๆ ของ Sound ฟังก์ชั่น และ Sound.Playing และ Sound.TimePosition ด้านล่าง


<tbody>
<tr>
<td>เสียง:เล่น()</td>
<td>ใช่</td>
<td>ค่าสุดท้ายที่ติดตั้งใน Lua (ค่าเริ่มต้น 0)</td>
</tr>
<tr>
<td>เสียง:Pause()</td>
<td>ปลอม</td>
<td>:-</td>
</tr>
<tr>
<td>เสียง: กลับเข้ามา()</td>
<td>ใช่</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

รวบรวม Sound รีเซ็ต Sound.Playing ให้เป็นจริง ไม่เปลี่ยนแปลง Sound.TimePosition และดังนั้นจึงสามารถใช้เพื่อรีเซ็นการเล่นเสียงที่หยุดโดยการใช้

ผลกระทบของระบบเสียงที่แตกต่างกันใน Sound.Playing และ Sound.TimePosition ปรากฏด้านล่าง


<tbody>
<tr>
<td>เสียง:เล่น()</td>
<td>ใช่</td>
<td>ค่าสุดท้ายที่ติดตั้งใน Lua (ค่าเริ่มต้น 0)</td>
</tr>
<tr>
<td>เสียง:Pause()</td>
<td>ปลอม</td>
<td>:-</td>
</tr>
<tr>
<td>เสียง: กลับเข้ามา()</td>
<td>ใช่</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

หยุด Sound ตั้งค่า Sound.Playing เป็น false แล้วตั้งค่า Sound.TimePosition เป็น 0

ผลกระทบของระบบเสียงที่แตกต่างกันใน Sound.Playing และ Sound.TimePosition ปรากฏด้านล่าง


<tbody>
<tr>
<td>เสียง:เล่น()</td>
<td>ใช่</td>
<td>ค่าสุดท้ายที่ติดตั้งใน Lua (ค่าเริ่มต้น 0)</td>
</tr>
<tr>
<td>เสียง:Pause()</td>
<td>ปลอม</td>
<td>:-</td>
</tr>
<tr>
<td>เสียง: กลับเข้ามา()</td>
<td>ใช่</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

เหตุการณ์ที่เกิดขึ้นเมื่อเวลา Sound ห่วงเหลี่ยมของวงจร ส่งคืน soundId และ numOfTimesLooped ให้คอนเทนต์ ID ของเสียงและจำนวนครั้งของการเล่นซ้ำ

เมื่อ Sound ถูกหยุดวงจรจะถูกรีเซ็ตหมายถึงการตั้งค่าต่อไปจะกลับมา 1 สำหรับ numOfTimesLooped

พารามิเตอร์

soundId: string

Class.Sound.SoundId ของ Sound ที่เปิดเครื่องเสียง

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.Looped ตั้งค่าเป็น true เมื่อพวกเขาเล่นต่อไปจนกว่าจะถึงจุดสิ้นสุด

เหตุการณ์นี้มักใช้เพื่อทำลายเสียงเมื่อมันเสร็จสิ้นการเล่น


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

ปิดนั่นหมายความว่ามันจะไม่เกิดขึ้นเมื่อเสียงถูกหยุดก่อนที่จะเล่นเสร็จสิ้นสำหรับการใช้งานนี้ Sound.Stopped

พารามิเตอร์

soundId: string

Class.Sound.SoundId ของ Sound ที่สิ้นสุดลงแล้ว


Loaded

เหตุการณ์ Sound.Loaded จะเกิดขึ้นเมื่อ Sound ได้รับการโหลด

หมายเหตุเหตุการณ์นี้จะเกิดขึ้นเฉพาะเมื่อเสียงถูกโหลด หมายถึงหากฟังเมื่อเสียงถูกโหลดแล้วจะไม่กลับมา ดังนั้นจึงเป็นการแนะนำให้ตรวจสอบ Sound.IsLoaded ก่อนที่จะเชื่อมต่อกับเหตุ

พารามิเตอร์

soundId: string

Class.Sound.SoundId ของ Sound ที่โหลด


ตัวอย่างโค้ด

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 ถูกหยุดใช้งานโดย Sound:Pause()

เช่นเดียวกับ Sound.Played , Sound.Resumed และ Sound.Stopped เฉพาะคุณสมบัติเสียงเท่านั้นที่จะทำให้เหตุการณ์เกิดขึ้น นี่หมายความว่า Pause จะเริ่มเ

พารามิเตอร์

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

Played

เปิดให้เมื่อ Sound ถูกเล่นโดยใช้ฟังก์ชัน Sound:Play()

เช่นเดียวกับ Class.Sound.Stopped``Class.Sound.Paused และ Sound.Resumed เฉพาะคุณสมบัติเสียงเท่านั้นท

พารามิเตอร์

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

Resumed

เปิดให้ใช้งานเมื่อ Sound ถูกเริ่มขึ้นใหม่โดยใช้ Sound:Resume()

เช่นเดียวกับ Sound.Played , Sound.Paused และ Sound.Stopped เฉพาะคุณสมบัติเสียงเท่านั้นที่จะทำให้เหตุการณ์เกิดขึ้น นี่หมายความว่า Resume จะเริ

พารามิเตอร์

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

เปิดให้บริการเมื่อ Sound ถูกหยุดทำงานเนื่องจากการใช้งาน Sound:Stop()

เช่นเดียวกับ Class.Sound.Played``Class.Sound.Paused และ Sound.Resumed เฉพาะคุณสมบัติเสียงเท่านั้นที่จะทำให้เหตุการณ์เกิดขึ้น นี่หมา

พารามิเตอร์

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