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

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

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?

4 comments

0

sound.looped = true

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

0

You could've just edited the music before uploading it to roblox.

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.

1 answer

✓ Accepted answer

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.

5 comments

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.

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.

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.

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.

0

I just tried it, and it works, thanks.

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