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
Accoast
(Accoast)
August 21, 2023, 2:04pm
#2
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()
2112Jay
(2112Jay)
August 21, 2023, 2:16pm
#5
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
I swear I could sec lemme hop on studio
Accoast
(Accoast)
August 21, 2023, 2:20pm
#9
Well you have to check on that. Sound also has this connection inside of it.
My memory is so bad. This is the code I used so it is the second huh…
wait(sound.TimeLength)
abs:
task.wait
also why put the task.wait I never got that just do wait
Accoast
(Accoast)
August 21, 2023, 2:23pm
#12
It’s alright, task.wait
is more preferrable though.
Task.wait is the new and improved version of wait. The difference between them is how it pauses the program, and task.wait wont throttle your code.
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
1 Like
Accoast
(Accoast)
August 21, 2023, 2:28pm
#17
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.
Rekotora3349
(Re_koFromSlovakia)
August 21, 2023, 2:33pm
#18
I use Script B so it makes sense and I didnt knew about the Script A …