Advertisement
HowToRoblox

AudioSpectrumHandler

Jul 9th, 2020
1,838
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.92 KB | None | 0 0
  1. local music = script:WaitForChild("Music")
  2.  
  3. local barsSize = 0.1
  4. local barsAmount = 100
  5.  
  6. local spectrumStartPos = Vector3.new(-6.27, 5.92, -3.67)
  7.  
  8. local audioSpectrumGroup = Instance.new("Model")
  9. audioSpectrumGroup.Parent = workspace
  10.  
  11. for i = 0, barsAmount - 1 do
  12.        
  13.     local bar = Instance.new("Part")
  14.    
  15.     bar.Size = Vector3.new(barsSize, barsSize, barsSize)
  16.     bar.Position = spectrumStartPos + Vector3.new(i * barsSize, 0, 0)  
  17.    
  18.     bar.Anchored = true
  19.     bar.CanCollide = false
  20.    
  21.     bar.Parent = audioSpectrumGroup
  22. end
  23.  
  24.  
  25. game:GetService("RunService").RenderStepped:Connect(function()
  26.    
  27.     local currentLoudness = music.PlaybackLoudness
  28.  
  29.     for i, audioSpectrumBar in pairs(audioSpectrumGroup:GetChildren()) do
  30.        
  31.         audioSpectrumBar.Size = Vector3.new(barsSize, currentLoudness/barsAmount + (math.random(-10, 10)/10), barsSize)
  32.  
  33.         audioSpectrumBar.Color = Color3.fromRGB(99, 0, math.clamp(currentLoudness, 0, 255))
  34.     end
  35. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement