So, I have this music randomizer script that runs on sound IDs, but it does not function correctly. To go into more detail, the Wait_Time variable uses a time length, but instead of playing the entire song and then moving on, it automatically thinks its done and gives about 0.5 seconds worth of the song, and that's only because of lines 10 - 13.. I seriously need help on this script, any answer would be very helpful.
Here is the script:
song_ID = {130776739,327081386,1375384985,685388224,755156652,214902446,437141803} randomizer = true song = Instance.new("Sound",workspace) song.Name = "TheLionLiar's DJ" Wait_Time = song.TimeLength inc = .01 asset_ID = "http://www.roblox.com/asset/?id=" function choose(tab) local obj = tab[math.random(1,#tab)] return obj end function play(s) if s:IsA("Sound") then local o = s.Volume s.Volume = 0 s:play() for i = 0,o,inc do wait() s.Volume = i end s.Volume = o end end function stop(s) if s:IsA("Sound") then local o = s.Volume for i = o,0,-inc do wait() s.Volume = i end s:stop() s.Volume = o end end local h = Instance.new("Hint",workspace) local Tool = game.ReplicatedStorage.tools.BoomBox local Handle = Tool:WaitForChild("Handle") local Remote = Tool:WaitForChild("Remote") local Sound = Handle:WaitForChild("Sound") counter = 1 if #song_ID > 0 then while true do wait() if randomizer then song.SoundId = asset_ID..""..choose(song_ID) else song.SoundId = asset_ID..""..song_ID[counter] end play(song) h.Text = "Song is being played..." wait(Wait_Time) h.Text = "Song Finished! TheLionLiar is picking a song for you..." stop(song) if counter >= #song_ID then counter = 1 else counter = counter + 1 end end end
Since you set the wait time to the TimeLength at the beginning of the script, it doesn't change when you change the song (it keeps it at whatever the TimeLength was at that instant). So, to fix this, you can replace
wait(Wait_Time)
with
wait(song.TimeLength)
to wait the TimeLength of that specific song.