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?
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.