Guest User

Feahren's Jukebox

a guest
Sep 6th, 2020
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.48 KB | None | 0 0
  1. --###----------[[DEVELOPER NOTES]]----------###--
  2. --[[
  3.  
  4. WRITTEN BY: FEAHREN.
  5.  
  6. DESCRIPTION: ENABLES THE ATTACHED SOUND-INSTANCE TO ITERATE—ADDITIONALLY AT RANDOM—THROUGH A GIVEN LIST OF SONGS.
  7.  
  8. ]]
  9.  
  10.  
  11. --###----------[[VARIABLES]]----------###--
  12. local SongIdList = {
  13.     --
  14. }
  15.  
  16. local SelectRandom = true --// Scrambles the SongList Array with a Fisher-Yate Shuffle.
  17.  
  18. local MusicObject = --// Object path - preferably the script's parent.
  19.  
  20.  
  21.  
  22. --###----------[[FUNCTIONS]]----------###--
  23. local function GetRandomSet(SongIdList)
  24.     for Iteration = #SongIdList, 1, -1 do
  25.         --------------
  26.         local RandomIndex = Random.new(tick()):NextInteger(1, Iteration)
  27.         --------------
  28.         SongIdList[Iteration] = SongIdList[RandomIndex]
  29.         SongIdList[RandomIndex] = SongIdList[Iteration]
  30.     end
  31.     ---------------
  32.     return SongIdList
  33. end
  34.  
  35. local function InitializeSongInteration()
  36.     local Set = (SelectRandom and GetRandomSet(SongIdList) or SongIdList)
  37.     --------------
  38.     for _,SongId in pairs(Set) do
  39.         --------------
  40.         MusicObject.SoundId = "https://www.roblox.com/asset/?id="..SongId
  41.         --------------
  42.         if not (MusicObject.IsLoaded) then
  43.             MusicObject.Loaded:Wait()
  44.         end
  45.         --------------
  46.         MusicObject:Play()
  47.         MusicObject.Ended:Wait()
  48.         --------------
  49.         MusicObject:Stop()
  50.     end
  51. end
  52.  
  53.  
  54.  
  55. --###----------[[INITIALIZATION]]----------###--
  56. InitializeSongIteration()
Advertisement
Add Comment
Please, Sign In to add comment