This should select an id from the table and play it (other part in a local script), but instead the song plays for like ~5 seconds and then another song is played, and it keeps repeating itself.
It never waits for an actual song to finish before playing a new one.
work.SoundBrick.Sound.Ended:connect(function() if not debounce then debounce = true -- added to debug work.SoundBrick.Sound:Stop() local randomSong = songs[math.random(1, #songs)] print(randomSong) wait(0.5) remotes.Events.PlaySong:FireAllClients(randomSong) -- add in params wait(4) debounce = false end end)
Get the length of the song (TimeLengh property) and put a wait() after the song is told to be played. The song should play fully.
Why it plays for 4 seconds, or 5, as you say, is because your debounce is set to 4. Meaning, after 4 seconds your script will re-loop and play a new song. Try to pick songs that are full length, which is 2 minutes, converted to 120 seconds. So for your wait, put wait(120), and it should work properly. This should be your final code:
work.SoundBrick.Sound.Ended:connect(function() if not debounce then debounce = true -- added to debug work.SoundBrick.Sound:Stop() local randomSong = songs[math.random(1, #songs)] print(randomSong) wait(0.5) remotes.Events.PlaySong:FireAllClients(randomSong) -- add in params wait(119.5) -- i did 199.5 because you have a .5 above this wait so this would make it exactly 120 seconds, which is 2 minutes, a full length roblox audio debounce = false end end)
Make sure to accept my answer if this helped.