Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Playing an audio straight after another?

So I have 2 audios, (2 parts of a song) by having a simple while (wait()) do loop is there a way to have the audio play straight after the previous audio has finished, currently, I'm just doing:

while (wait()) do
	if (sound.Ended) then
		-- play next part of song
	end
end

but the only problem is that there's a tiny delay, cut if you like where the audio isn't playing, I'm presuming this is where the wait() is, but it is still noticeable.

Edit:

The sound is locally done, to minimise the delay as much as possible.

2 answers

There is an event of Sound objects named Ended that fires when a sound is stopped or the end of the sound was reached. This is exactly what you want in this case:

sound.Ended:connect(function()
	-- play next sound
end)

2 comments

0

Still has a split second delay though.

0

This fires immediately after the sound stops playing, there is no way to be any more precise.

So, I'd like to take a shot at this one. I don't have access to a PC right now, but I have access to the ROBLOX Wiki.

Basically, I have a feeling that the TimeLength value in Sound objects can be used for this exact purpose.

Instead of this...

sound.Ended:connect(function()
    -- play next sound
end)

Try this. Replace ### with a number you'd like. Adjust it until the delay is gone.

while true do
	wait(.1)
	if sound.TimePosition = sound.TimeLength - ### then
	sound2:Play()
end

Basically, what this does is that, every 0.1 seconds, the script checks to see if the TimePosition value of the sound is equal to the TimeLength minus what you put as ###. If the script finds that the TimePosition is equal to that, it plays the next sound.

Not entirely sure if it will work, but still worth a try.

This discussion is preserved as it was. New answers, comments, and votes are closed.