Waiting For Sound

I’ll keep this short:

Which line of code do you guys think works better? Take a look:

Script A:

workspace.Sound.Ended:Wait()

Script B:

task.wait(workspace.Sound.TimeLength)

If you know which one’s better, please comment it down below, because I need to know this. Thank you.

2 Likes

First looks cleaner to me, as we can instantly see to which sound we will wait to end.

What if the sound is looped?

According to Roblox, the Ended event won’t fire if the sound is looped, because it plays immediately after it completes.

I don’t know which is better but I always use the first one.
edit: I do it a little changed its like a combination of both its
workspace.Sound.TimeLength:Wait()

1st version (A) is what I like to use. But I also like to define where it is …

local sound = workspace.Sound
sound:Play()
sound.Ended:Wait()

This is probably inefficient and creates problems

You can’t do that pal…
image

I swear I could sec lemme hop on studio

Well you have to check on that. Sound also has this connection inside of it.
image

My memory is so bad. This is the code I used so it is the second huh…
wait(sound.TimeLength)

also why put the task.wait I never got that just do wait

It’s alright, task.wait is more preferrable though.

What I meant is:

task.wait(workspace.Sound.TimeLength)

I solved the problem 20 minutes ago, but I’m still curious as to which method is better. The first option can’t be used if your sound is looped, so?

Ok, Thanks For The Extra Info :smiley:

1 Like

That was an answer to @fortnite_fan67154.
Anyway, waiting for the connection seems more responsive to me, as the sound might not instantly load and cut in the end.

Conclusion.
If not looped:

workspace.Sound.Ended:Wait()

If is looped:

workspace.Sound.DidLoop:Wait() -- :: will keep playing!

Also some additional info.
DidLoop returns:

local SoundId, AmountOfLoopsPlayed = workspace.Sound.DidLoop:Wait() 

And Ended returns SoundId only.

I use Script B so it makes sense and I didnt knew about the Script A