Advertisement
HowToRoblox

MusicGuiHandler

Jul 1st, 2020
3,819
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.12 KB | None | 0 0
  1. local mps = game:GetService("MarketplaceService")
  2.  
  3.  
  4. local bg = script.Parent
  5.  
  6. local playBtn = bg:WaitForChild("PlayButton")
  7. local loopingBtn = bg:WaitForChild("LoopingToggle")
  8. local timePos = bg:WaitForChild("MusicTimePos")
  9.  
  10. local volumeToggleBtn = bg:WaitForChild("VolumeToggle")
  11. local volumeUp = bg:WaitForChild("VolumeUp")
  12. local volumeDown = bg:WaitForChild("VolumeDown")
  13. local volumeAmount = bg:WaitForChild("VolumeAmount")
  14.  
  15. local musicName = bg:WaitForChild("MusicName")
  16. local musicOwner = bg:WaitForChild("MusicOwner")
  17.  
  18. local musicInputBox = bg:WaitForChild("MusicInput")
  19.  
  20. local music = bg:WaitForChild("Music")
  21.  
  22.  
  23. local isLooping = false
  24. local isPlaying = false
  25. local isMuted = false
  26.  
  27. local currentVolume = 10
  28. local minVolume = 0
  29. local maxVolume = 10
  30.  
  31.  
  32. musicName.Text = ""
  33. musicOwner.Text = ""
  34. volumeAmount.Text = "10"
  35. timePos.Text = "00:00"
  36.  
  37.  
  38. musicInputBox.FocusLost:Connect(function()
  39.    
  40.     local input = musicInputBox.Text
  41.     local success, info = pcall(mps.GetProductInfo, mps, input)
  42.    
  43.     if success and info.AssetTypeId == 3 then
  44.        
  45.         music:Stop()
  46.         isPlaying = false  
  47.         playBtn.Image = game.ReplicatedStorage.Decals.Play.Texture
  48.        
  49.         music.SoundId = "rbxassetid://" .. input
  50.        
  51.         musicName.Text = info.Name
  52.         musicOwner.Text = " by " .. info.Creator.Name
  53.     end
  54. end)
  55.  
  56. playBtn.MouseButton1Click:Connect(function()
  57.    
  58.     if isPlaying then
  59.         isPlaying = false
  60.        
  61.         playBtn.Image = game.ReplicatedStorage.Decals.Play.Texture
  62.         music:Pause()
  63.        
  64.     else
  65.         isPlaying = true
  66.        
  67.         playBtn.Image = game.ReplicatedStorage.Decals.Pause.Texture
  68.         music:Resume()
  69.     end
  70. end)
  71.  
  72. loopingBtn.MouseButton1Click:Connect(function()
  73.    
  74.     if isLooping then
  75.         isLooping = false
  76.        
  77.         music.Looped = false
  78.        
  79.         loopingBtn.ImageColor3 = Color3.fromRGB(95, 95, 95)
  80.        
  81.     else
  82.        
  83.         isLooping = true
  84.        
  85.         music.Looped = true
  86.        
  87.         loopingBtn.ImageColor3 = Color3.fromRGB(255, 255, 255)
  88.     end
  89. end)
  90.  
  91. volumeToggleBtn.MouseButton1Click:Connect(function()
  92.    
  93.     if isMuted then
  94.         isMuted = false
  95.        
  96.         volumeToggleBtn.ImageColor3 = Color3.fromRGB(95, 95, 95)
  97.        
  98.         music.Volume = currentVolume / 10
  99.        
  100.     else
  101.         isMuted = true
  102.        
  103.         volumeToggleBtn.ImageColor3 = Color3.fromRGB(255, 255, 255)
  104.        
  105.         music.Volume = 0
  106.     end
  107. end)
  108.  
  109. volumeUp.MouseButton1Click:Connect(function()
  110.    
  111.     isMuted = false
  112.     volumeToggleBtn.ImageColor3 = Color3.fromRGB(95, 95, 95)
  113.    
  114.     currentVolume = math.clamp(currentVolume + 1, minVolume, maxVolume)
  115.    
  116.     music.Volume = currentVolume / 10
  117.     volumeAmount.Text = currentVolume
  118. end)
  119. volumeDown.MouseButton1Click:Connect(function()
  120.    
  121.     isMuted = false
  122.     volumeToggleBtn.ImageColor3 = Color3.fromRGB(95, 95, 95)
  123.    
  124.     currentVolume = math.clamp(currentVolume - 1, minVolume, maxVolume)
  125.    
  126.     music.Volume = currentVolume / 10
  127.     volumeAmount.Text = currentVolume
  128. end)
  129.  
  130. game:GetService("RunService").RenderStepped:Connect(function()
  131.    
  132.     local musicTimePos = math.floor(music.TimePosition)
  133.    
  134.     local musicTimePosSecs = musicTimePos % 60
  135.     local musicTimePosMins = math.floor(musicTimePos / 60)
  136.    
  137.     if string.len(musicTimePosSecs) < 2 then musicTimePosSecs = "0" .. musicTimePosSecs end
  138.     if string.len(musicTimePosMins) < 2 then musicTimePosMins = "0" .. musicTimePosMins end
  139.    
  140.     timePos.Text = musicTimePosMins .. ":" .. musicTimePosSecs
  141. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement