Advertisement
Guest User

LocalMusic

a guest
Apr 9th, 2020
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.58 KB | None | 0 0
  1. -- Script by lnsertYourself
  2. local minDanceFloorLight = 150
  3. local maxDanceFloorLight = 300
  4.  
  5. local minParticleEmit = 350
  6. local particleRate = 500
  7.  
  8. local minLightEmit = 400
  9.  
  10. --// DO NOT MODIFY BEYOND THIS POINT \\--
  11. local music = script:WaitForChild("Music")
  12. local renderStepped = game:GetService("RunService").RenderStepped
  13.  
  14. local danceFloors = workspace:WaitForChild("DanceFloors"):GetChildren()
  15. local function setDancefloorTransparency(transparency)
  16.     for _, floor in ipairs(danceFloors) do
  17.         floor.Transparency = transparency
  18.     end
  19. end
  20.  
  21. local particleEmitters = workspace:WaitForChild("ParticleEmitters"):GetChildren()
  22. local function setParicleRate(rate)
  23.     for _, part in ipairs(particleEmitters) do
  24.         part.ParticleEmitter.Rate = rate
  25.     end
  26. end
  27.  
  28. local lights = workspace:WaitForChild("Lights"):GetChildren()
  29. local function setLightEnabled(bool)
  30.     for _, light in ipairs(lights) do
  31.         light.SpotLight.Enabled = bool
  32.     end
  33. end
  34.  
  35. renderStepped:Connect(function()
  36.     local loudness = music.PlaybackLoudness
  37.    
  38.     -- Dance Floor
  39.     setDancefloorTransparency(loudness > maxDanceFloorLight and 0 or loudness > minDanceFloorLight and
  40.         math.abs((loudness - maxDanceFloorLight)/1000) or .1)
  41.    
  42.     -- Particle Emitters
  43.     setParicleRate(loudness >= minParticleEmit and particleRate or 0)
  44.    
  45.     -- Lights
  46.     setLightEnabled(loudness > minLightEmit and true or false)
  47. end)
  48.  
  49. game.ReplicatedStorage:WaitForChild("SongEvent").OnClientEvent:Connect(function(songId, t)
  50.     music:Stop()
  51.     music.SoundId = songId
  52.     if not music.IsLoaded then music.Loaded:Wait() end
  53.     music.TimePosition = t
  54.     music:Play()
  55. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement