PotatoSaiyan

Colorful Ring Visualizer

Mar 8th, 2017
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.22 KB | None | 0 0
  1. --[[Credits:
  2. fang - For inspiration
  3. victiny1223 - because I scripted it.
  4. idk - have fun I guess
  5. --]]
  6. lplr = game:GetService('Players').LocalPlayer
  7. runservice = game:GetService('RunService')
  8. lcharacter = lplr.Character
  9. repeat wait() until lcharacter
  10. lhumpart = lcharacter:FindFirstChild("Torso")
  11. mode = ("Default")
  12. --[[Commands:
  13. color(1-3 depending on which color you'd like to change) red green blue - Changes that color to the red green blue code provided
  14. mode (Default, Still, Large, Wave) - Changes the audio visualiser mode
  15. playmusic (MUSICID) - Plays the music/sound with that corresponding asset id
  16. stopmusic - Stops all music/sounds including your own.
  17. --]]
  18. --Default Colors
  19. colors = {
  20. {r = 0, g = 0, b = 255},
  21. {r = 255, g = 0, b = 0},
  22. {r = 255, g = 255, b = 0}
  23. }
  24. --Circle of Parts
  25. smoothOut = function(basepart)
  26. local f = {'Front','Back','Bottom','Top','Left','Right'}
  27. if basepart:IsA("BasePart") then
  28. for _, face in ipairs(f) do
  29. basepart[face .. 'Surface'] = Enum.SurfaceType.Smooth
  30. end
  31. end
  32. end
  33. colorLerp = function(obj, targetColor)
  34. local tcolor = targetColor.Color
  35. local ccolor = obj.BrickColor.Color
  36. for i = 0, 1, .1 do
  37. obj.BrickColor = BrickColor.new(ccolor:Lerp(tcolor, i))
  38. wait(1/60)
  39. end
  40. end
  41. updateBlock = function(p, angle)
  42. p.Parent = lcharacter
  43. p.CanCollide = false
  44. p.Material = Enum.Material.Neon
  45. p.Anchored = true
  46. if not sound then
  47. p.Size = Vector3.new(1, 1, 1)
  48. p.CFrame = lhumpart.CFrame * CFrame.Angles(0, math.rad(angle), 0)
  49. * CFrame.new(20, 0, 0)
  50. elseif sound then
  51. if mode == 'Default' then
  52. p.Size = Vector3.new(1, (sound.PlaybackLoudness/math.random(10, 75)), 1)
  53. elseif mode == 'Wave' then
  54. p.Size = Vector3.new(1, (sound.PlaybackLoudness/angle), 1)
  55. elseif mode == 'Still' then
  56. p.Size = Vector3.new(1, (sound.PlaybackLoudness/bricks[angle]), 1)
  57. elseif mode == 'Large' then
  58. p.Size = Vector3.new(1, (sound.PlaybackLoudness), 1)
  59. end
  60. p.CFrame = lhumpart.CFrame * CFrame.Angles(0, math.rad(angle), 0)
  61. * CFrame.new(20, p.Size.Y/2, 0)
  62. if sound.PlaybackLoudness > 0 then
  63. colorLerp(p, BrickColor.new(colors[1]['r'],colors[1]['g'],colors[1]['b']))
  64. elseif sound.PlaybackLoudness >= 200 then
  65. colorLerp(p, BrickColor.new(colors[2]['r'],colors[2]['g'],colors[2]['b']))
  66. elseif sound.PlaybackLoudness >= 400 then
  67. colorLerp(p, BrickColor.new(colors[3]['r'],colors[3]['g'],colors[3]['b']))
  68. end
  69. end
  70. end
  71. bricks = {}
  72. lhumpart.Anchored = true
  73. setupVisualiser = function()
  74. for angle = 1, 360 do
  75. if angle % 5 == 0 then
  76. local p = Instance.new("Part")
  77. bricks[angle] = math.random(10, 75)
  78. smoothOut(p)
  79. runservice:BindToRenderStep('updateBlock', Enum.RenderPriority.First.Value, function()
  80. updateBlock(p, angle)
  81. end)
  82. end
  83. end
  84. end
  85. setupVisualiser()
  86. lhumpart.Anchored = false
  87. sound = nil
  88. playmusic = function(id)
  89. if sound then
  90. sound:Remove()
  91. sound = nil
  92. end
  93. local sound = Instance.new("Sound")
  94. sound.SoundId = ('rbxassetid://' .. id)
  95. sound.Volume = 5
  96. sound.Parent = workspace
  97. sound:Play()
  98. return sound
  99. end
  100. lcharacter:FindFirstChild("Humanoid").Died:connect(function()
  101. runservice:UnbindFromRenderStep('updateBlock')
  102. end)
  103. lplr.CharacterAdded:connect(function()
  104. lcharacter = lplr.Character
  105. lhumpart = lcharacter:FindFirstChild("Torso")
  106. setupVisualiser()
  107. end)
  108. removeSounds = function(directory)
  109. for _, obj in pairs(directory:GetChildren()) do
  110. pcall(function()
  111. if obj:IsA("Sound") then
  112. obj:Remove()
  113. sound = nil
  114. elseif #obj:GetChildren() > 0 then
  115. removeSounds(obj)
  116. end
  117. end)
  118. end
  119. end
  120.  
  121. checkMessage = function(inputMsg)
  122. local cmd = inputMsg:match('(%a+)')
  123. local arg = inputMsg:match('%a+%s(%w+)')
  124. local color,r,g,b = inputMsg:match('%a+(%d)%s(%d+)%s(%d+)%s(%d+)')
  125. if cmd and arg then
  126. if cmd:lower() == 'playmusic' then
  127. sound = playmusic(tonumber(arg))
  128. elseif cmd:lower() == 'mode' then
  129. mode = arg
  130. end
  131. elseif cmd:lower() == 'stopmusic' then
  132. removeSounds(workspace)
  133. elseif color and r and g and b then
  134. color = tonumber(color)
  135. r = tonumber(r)
  136. g = tonumber(g)
  137. b = tonumber(b)
  138. if colors[color] then
  139. local c = colors[color]
  140. c['r'] = r
  141. c['g'] = g
  142. c['b'] = b
  143. end
  144. end
  145. end
  146. lplr.Chatted:connect(checkMessage)
Add Comment
Please, Sign In to add comment