DrawingJhon

Audio visualizer (Local sided)

Dec 24th, 2020 (edited)
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.57 KB | None | 0 0
  1. print("Audio Visualizer by DrawingJhon")
  2.  
  3. local player = game:GetService("Players").LocalPlayer
  4. local mouse = player:GetMouse()
  5. local render = game:GetService("RunService").RenderStepped
  6. script.Parent = player.PlayerGui
  7. local prefix = ","
  8.  
  9. local plVol = 0
  10. local parts = {}
  11. local lights = {}
  12. local lastPosMouse
  13.  
  14. local model = Instance.new("Model", workspace)
  15. model.Name = "AudioSpectrum"
  16.  
  17. local lastModel = model
  18. local sound = Instance.new("Sound", model)
  19. sound.Name = "Audio"
  20. sound.Looped = true
  21.  
  22. spawn(function()
  23.     wait(1.5)
  24.     while true do
  25.         if model.Parent == nil then
  26.             model = Instance.new("Model", workspace)
  27.             model.Name = "AudioSpectrum"
  28.             sound = Instance.new("Sound", model)
  29.             sound.Name = "Audio"
  30.             sound.Looped = true
  31.         end
  32.         wait()
  33.     end
  34. end)
  35.  
  36. local colors = {
  37.     red = true;
  38.     green = false;
  39.     blue = false;
  40.     white = false;
  41.     black = false;
  42.     rainbow = false;
  43. }
  44. function cFalse()
  45.     colors.red = false
  46.     colors.green = false
  47.     colors.blue = false
  48.     colors.white = false
  49.     colors.black = false
  50.     colors.rainbow = false
  51. end
  52. local RainbowColor = Color3.new()
  53. local RECode = math.random()
  54.  
  55. function StartRainbowify()
  56.     coroutine.wrap(function()
  57.         local code = math.random()
  58.         RECode = code
  59.         local RealWait = wait
  60.         local function wait(num)
  61.             if RECode == code then
  62.                 return RealWait(num)
  63.             end
  64.             coroutine.yield()
  65.         end
  66.         while true do
  67.                 RainbowColor = Color3.new(255/255,0/255,0/255)
  68.                 for i = 0,255,10 do
  69.                 wait()
  70.                 RainbowColor = Color3.new(255/255,i/255,0/255)
  71.                 end
  72.                 for i = 255,0,-10 do
  73.                 wait()
  74.                 RainbowColor = Color3.new(i/255,255/255,0/255)
  75.             end
  76.                 for i = 0,255,10 do
  77.                 wait()
  78.                 RainbowColor = Color3.new(0/255,255/255,i/255)
  79.                 end
  80.             for i = 255,0,-10 do
  81.                 wait()
  82.                 RainbowColor = Color3.new(0/255,i/255,255/255)
  83.             end
  84.             for i = 0,255,10 do
  85.                 wait()
  86.                 RainbowColor = Color3.new(i/255,0/255,255/255)
  87.             end
  88.             for i = 255,0,-10 do
  89.                 wait()
  90.                 RainbowColor = Color3.new(255/255,0/255,i/255)
  91.                 end
  92.         end
  93.     end)()
  94. end
  95.  
  96. function msgFunc(msg)
  97.     local p = prefix
  98.     if msg:lower():sub(1,6) == p.."play " then
  99.         local id = msg:sub(7)
  100.         if model:findFirstChildOfClass("Sound") then
  101.             local sound = model:findFirstChildOfClass("Sound")
  102.             sound.Name = "Audio"
  103.             sound:Stop()
  104.             sound.SoundId = "rbxassetid://"..id
  105.             sound:Play()
  106.         else
  107.             sound = Instance.new("Sound", model)
  108.             sound.Name = "Audio"
  109.             sound.Looped = true
  110.             sound.SoundId = "rbxassetid://"..id
  111.             sound:Play()
  112.         end
  113.     end
  114.     if msg:lower():sub(1,5) == p.."stop" then
  115.         sound:Stop()
  116.     end
  117.     if msg:lower():sub(1,7) == p.."color " then
  118.         local msg = msg:sub(8)
  119.         if msg:lower() == "red" then
  120.             cFalse()
  121.             colors.red = true
  122.         end
  123.         if msg:lower() == "blue" then
  124.             cFalse()
  125.             colors.blue = true
  126.         end
  127.         if msg:lower() == "green" then
  128.             cFalse()
  129.             colors.green = true
  130.         end
  131.         if msg:lower() == "black" then
  132.             cFalse()
  133.             colors.black = true
  134.         end
  135.         if msg:lower() == "white" then
  136.             cFalse()
  137.             colors.white = true
  138.         end
  139.         if msg:lower() == "rainbow" then
  140.             cFalse()
  141.             StartRainbowify()
  142.             colors.rainbow = true
  143.         end
  144.     end
  145.     if msg:lower():sub(1,8) == p.."volume " then
  146.         sound.Volume = msg:sub(9)
  147.     end
  148.     if msg:lower():sub(1,7) == p.."pitch " then
  149.         sound.Pitch = msg:sub(8)
  150.     end
  151.     if msg:lower() == p.."clear" then
  152.         for i = 1,#parts do
  153.             parts[i]:Destroy()
  154.         end
  155.     end
  156. end
  157.  
  158. player.Chatted:Connect(function(msg)
  159.     if msg:sub(1,3) == "/e " then
  160.         msgFunc(msg:sub(4))
  161.     else
  162.         msgFunc(msg)
  163.     end
  164. end)
  165.  
  166. local function mPart(name, pos, bc)
  167.     local part = Instance.new("Part", player.Character)
  168.     part.Anchored = true
  169.     part.Transparency = 0
  170.     part.Name = name
  171.     part.CFrame = CFrame.new(pos)
  172.     part.Color = bc
  173.     part.Material = "Neon"
  174.     part.TopSurface = "Smooth"
  175.     part.BottomSurface = "Smooth"
  176.     return part
  177. end
  178.  
  179. function fireAction(wht, data)
  180.     if wht == "Vol" then
  181.         for i, v in pairs(parts) do
  182.             if v:IsA("BasePart") then
  183.                 if sound.Parent == nil then
  184.                     v.Size = Vector3.new(1, 1, 1)
  185.                 else
  186.                     v.Size = Vector3.new(1, data/math.random(10,25), 1)
  187.                 end
  188.             end
  189.         end
  190.         plVol = data
  191.     end
  192.     if wht == "mouseDown" then
  193.         if data == lastPosMouse then return else lastPosMouse = data end
  194.         local brick = mPart("Part", data, Color3.new(0, 0, 0))
  195.         brick.CanCollide = false
  196.         brick.Size = Vector3.new(1, 1, 1)
  197.         table.insert(parts, brick)
  198.         local light = Instance.new("PointLight", brick)
  199.         light.Color = brick.BrickColor.Color
  200.         light.Range = 0
  201.         light.Enabled = true
  202.         light.Shadows = true
  203.         light.Brightness = 0
  204.         table.insert(lights, light)
  205.     end
  206. end
  207.  
  208.  
  209. spawn(function()
  210.     while true do
  211.         for i, v in pairs(lights) do
  212.             v.Enabled = true
  213.             v.Brightness = plVol/19
  214.             v.Range = plVol/15
  215.             v.Color = parts[i].Color
  216.         end
  217.         for _, v in pairs(parts) do
  218.             if sound.Parent == nil or sound.IsPlaying == false then
  219.                 v.BrickColor = BrickColor.new(Color3.new(0, 0, 0)) v.Size = Vector3.new(1, 1, 1)
  220.             elseif colors.red == true then
  221.                 v.BrickColor = BrickColor.new(Color3.new(plVol/200, 0, 0))
  222.             elseif colors.green == true then
  223.                 v.BrickColor = BrickColor.new(Color3.new(0, plVol/200, 0))
  224.             elseif colors.blue == true then
  225.                 v.BrickColor = BrickColor.new(Color3.new(0, 0, plVol/200))
  226.             elseif colors.white == true then
  227.                 v.BrickColor = BrickColor.new(Color3.new(255, 255, 255))
  228.             elseif colors.black == true then
  229.                 v.BrickColor = BrickColor.new(Color3.new(0, 0, 0))
  230.             elseif colors.rainbow == true then
  231.                 v.Color = RainbowColor
  232.             end
  233.         end
  234.         render:Wait()
  235.     end
  236. end)
  237.  
  238. local db = false
  239. local audio = sound
  240.    
  241. repeat wait() until model ~= nil
  242.  
  243. mouse.Button1Down:Connect(function()
  244.     db = false
  245.     repeat
  246.         if db == true then break end
  247.         fireAction("mouseDown", mouse.Hit.p)
  248.         wait()
  249.     until db == true
  250. end)
  251. mouse.Button1Up:connect(function()
  252.     db = true
  253. end)
  254.  
  255. render:Connect(function()
  256.     for i = 1,#parts do
  257.         if parts[i] ~= nil and parts[i].ClassName == "Part" and parts[i].Parent ~= nil then
  258.             parts[i].LocalTransparencyModifier = 0
  259.         end
  260.     end
  261. end)
  262. spawn(function()
  263.     while true do
  264.         repeat render:Wait() until audio.IsPlaying
  265.         local vol = audio.PlaybackLoudness
  266.         fireAction("Vol", vol)
  267.         workspace.CurrentCamera.FieldOfView = 70 - vol/100
  268.     end
  269. end)
  270. wait(.1)
  271. print([[Commands:
  272. ]]..prefix..[[cmds
  273. ]]..prefix..[[play < SongId > - Play song id
  274. ]]..prefix..[[color < red / green / blue / rainbow / white / black > - Change Audio Visualizer color
  275. ]]..prefix..[[volume < number > - Change song volume
  276. ]]..prefix..[[pitch < number > - Change song pitch
  277. ]]..prefix..[[stop - Stop song]])
  278. print("Note: You can use silent commands")
Add Comment
Please, Sign In to add comment