Hello. First of all, I’m using this script: [Release] Play Custom Sounds for Interactions
For those who doesn’t know how that works it simply starts playing sound from .ogg file. The problem is there is no loop option or anything like that, so when file ends the music is gone until another request is send. I wanted to make a function which will let playing this music in loop but recently I was told that TerminateThisThread() doesn’t work in FiveM, so I can’t use it that much because it will create many threads and I already had tons of problems with that because it was crashing my script in random moments because of that.
function PlayMusicInLoop(index, audio, length)
KeepPlaying[index] = true
Citizen.CreateThread(function()
while KeepPlaying[index] do
TriggerEvent('LIFE_CL:Sound:PlayOnOne', audio, 0.05)
Citizen.Wait(length)
end
TerminateThisThread()
end)
end
And this is why I’m asking if anyone has a better idea for the structure in this little function. I really appreciate any tips