Advertisement
DrawingJhon

Audio visualizer (Server sided FE)

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