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

How to make a non-looping audio loop more seamlessly?

Asked by 5 years ago
Edited 5 years ago

Hi. I'm making a game with a boss fight theme. I wanted to make it so that instead of looping back to the beginning, it loops to a different point in the song.

local Song = script.Parent
local LoopPoint = 29.86
Song.DidLoop:Connect(function(ok)
Song.TimePosition = LoopPoint
end)

Although it works, there still is a bit of a gap whenever it loops, which isnt too bothersome, but is something I want to iron out for presentation sake. Is there a better way of going about this, or is this as good as it's going to get?

0
sound.looped = true iiomqitzkinqnaenaexx 0 — 5y
0
I presume it would have a debounce the Event you’re using, try forcing it to play again, or maybe the song has a drifted ending Ziffixture 6913 — 5y
0
You could've just edited the music before uploading it to roblox. Sorukan 240 — 5y
0
1) It is looped. 2) The ending is abrubt since its 8 bit. How could I implement debounce into this application? 3) I did, in fact, edit it down. I wanted to save as much money as possible, which is why im doing it this way. krankycaat 11 — 5y

1 answer

Log in to vote
0
Answered by
SteamG00B 1633 Moderation Voter
5 years ago
Edited 5 years ago

I definitely made it too complicated the first time. I will explain what's going on with comments this time because it is much simpler.

local sound = script.Parent.Sound

wait(3)--this was just for testing purposes, you can remove this
for x=1,3 do --loops the song 3 times
    sound:Play()
    wait(sound.TimeLength)--waits for the song length before playing it immediately after
end

Now if you want the boss battle music to fade into some other music after it stops looping, then you can use this instead of the one above:

local sound = script.Parent.Sound
local sound2 = script.Parent.Sound2
local loopCount = 2 --allows you to choose how many times to loop the boss battle music
local Fade = 2 --how many seconds it should take to fade into the next song

sound.Volume=1
sound2.Volume=0

local function fade(s1, s2,duration) --song1, song2, duration of the fading
    for i = 1,50 do
        wait(duration/50)
        s1.Volume = s1.Volume - 0.05
        s2.Volume = s2.Volume + 0.05
    end
end

wait(3)--just for my testing purposes, you can remove this

for x=1,loopCount do --loops the song 2 times before fading into the next one
    if x == loopCount then
        sound:Play()
        repeat wait() until sound.TimePosition > sound.TimeLength - Fade --waits for first song to near its end before playing
        sound2:Play() --this volume is previously set to 0 so we play it now
        fade(sound,sound2,Fade) --both sounds are playing so we now fade song1 out and song2 in.
    else
        sound:Play()    
        wait(sound.TimeLength)
    end
end


If this solves your problem, then please mark it as the accepted answer.

0
Looking back on this, it's more complicated than it needs to be for your problem, so I'll see if I can actually change it up a bit to make it a lot more simpler. SteamG00B 1633 — 5y
0
Thank you, that helps massively. Ill try it out tomorrow when i get the chance, i know by then your edits will be posted. krankycaat 11 — 5y
0
Thanks. I know it didnt fully answer my question, but I think that setting the timeposition before it plays should suffice? I did want it to loop to a certain point in the song but do appreciate the effort for a stranger on the internet. krankycaat 11 — 5y
0
Did this not work for your song? Do you have the rbxID of the audio you want to loop? I could fine tune this for you if it isn't working well for you. SteamG00B 1633 — 5y
0
I just tried it, and it works, thanks. krankycaat 11 — 5y
Ad

Answer this question