Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Playing an audio straight after another?

Asked by
iFlusters 355 Moderation Voter
7 years ago
Edited 7 years ago

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

Log in to vote
0
Answered by
BlackJPI 2658 Snack Break Moderation Voter Community Moderator
7 years ago
Edited 7 years ago

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)
0
Still has a split second delay though. iFlusters 355 — 7y
0
This fires immediately after the sound stops playing, there is no way to be any more precise. BlackJPI 2658 — 7y
Ad
Log in to vote
0
Answered by 7 years ago

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.

Answer this question