Advertisement
Stefanuk12

music cmds

Mar 21st, 2020
3,396
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.51 KB | None | 0 0
  1. local HS = game:GetService('HttpService')
  2. local musicTable = HS:JSONDecode(game:HttpGetAsync('https://epicgameronmylevel696969.000webhostapp.com/Data.json'))
  3.  
  4. function testContentDeleted(songid)
  5.     local sound = Instance.new("Sound", game:GetService("Lighting"))
  6.     sound.SoundId = "rbxassetid://"..songid
  7.     sound.Volume = 0
  8.     sound:Play()
  9.     wait(0.1)
  10.     if sound.TimeLength < 0.05 then
  11.         sound:Destroy()    
  12.         return false
  13.     else
  14.         sound:Destroy()    
  15.         return true
  16.     end
  17. end
  18.  
  19. function updateMusicTable()
  20.     for i,v in pairs(musicTable) do
  21.         if testContentDeleted(musicTable[i].SoundId) == false then
  22.             musicTable[i] = nil
  23.         end
  24.     end
  25. end
  26.  
  27. function changeMusicTable(Index, Name, SoundId)
  28.     updateMusicTable()
  29.     if musicTable[Index] then
  30.         if SoundId then
  31.             musicTable[Index].SoundId = SoundId
  32.         end
  33.         if Name then
  34.             musicTable[Index].Name = Name
  35.         end
  36.     end
  37. end
  38.  
  39. function addMusicTable(Name, SoundId)
  40.     updateMusicTable()
  41.     local Index = #musicTable + 1
  42.     musicTable[Index] = {}
  43.     musicTable[Index].Name = Name
  44.     musicTable[Index].SoundId = SoundId
  45. end
  46.  
  47. function removeMusicTable(Index)
  48.     updateMusicTable()
  49.     table.remove(musicTable, Index)
  50. end
  51.  
  52. function playMusic(num)
  53.     updateMusicTable()
  54.     if musicTable[num] then
  55.         game:GetService("Players"):Chat(":music ".. tostring(musicTable[num].SoundId))
  56.         print('Now playing:', musicTable[num].Name)
  57.         return musicTable[num].Name
  58.     end
  59. end
  60.  
  61. function getMusic()
  62.     updateMusicTable()
  63.  
  64.     for i=1, #musicTable do
  65.         if musicTable[i] then
  66.             wait()
  67.             print("You can play", tostring(musicTable[i].Name), "- Just use number:", i)
  68.         end
  69.     end
  70. end
  71.  
  72. local prefix = ":"
  73. game:GetService("Players").LocalPlayer.Chatted:Connect(function(msg)
  74.     if string.sub(msg, 1, 6) == (prefix.."play ") then
  75.         if musicTable[tonumber(string.sub(msg, 7))] then
  76.             playMusic(tonumber(string.sub(msg, 7)))
  77.         end
  78.     end
  79. end)
  80.  
  81. game:GetService("Players").LocalPlayer.Chatted:Connect(function(msg)
  82.     if string.sub(msg, 1) == (prefix.."getmusic") then
  83.         getMusic()
  84.     end
  85. end)
  86.  
  87. game:GetService("Players").LocalPlayer.Chatted:Connect(function(msg)
  88.     if string.sub(msg, 1) == (prefix.."getmusichelp") then
  89.         print([[*Make sure you have admin*
  90.        
  91.             :getmusic - gets all of the playable music
  92.             :play [number] - plays a certain song from the playable music list
  93.         ]])
  94.     end
  95. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement