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.
01 | work.SoundBrick.Sound.Ended:connect( function () |
02 | if not debounce then |
03 | debounce = true |
04 | -- added to debug |
05 | work.SoundBrick.Sound:Stop() |
06 |
07 | local randomSong = songs [ math.random( 1 , #songs) ] |
08 | print (randomSong) |
09 | wait( 0.5 ) |
10 | remotes.Events.PlaySong:FireAllClients(randomSong) -- add in params |
11 | wait( 4 ) |
12 | debounce = false |
13 | end |
14 | 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:
01 | work.SoundBrick.Sound.Ended:connect( function () |
02 | if not debounce then |
03 | debounce = true |
04 | -- added to debug |
05 | work.SoundBrick.Sound:Stop() |
06 |
07 | local randomSong = songs [ math.random( 1 , #songs) ] |
08 | print (randomSong) |
09 | wait( 0.5 ) |
10 | remotes.Events.PlaySong:FireAllClients(randomSong) -- add in params |
11 | 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 |
12 | debounce = false |
13 | end |
14 | end ) |
Make sure to accept my answer if this helped.