I wanted to learn how to make stuff react to audio. I did some research the property I needed to loop into was PlaybackLoudness. I tested out this feature while changing the range of a PointLight on a part and it worked! Here is the code:
while wait() do -- \/ Located inside sound
workspace.SoundPart.PointLight.Range = script.Parent.PlaybackLoudness/25
end
The problem with the script above is it updates REALLY REALLY quicky and the light flashes a ton! So I tried lerping.
To implement a lerp, I made this code below:
script.Parent:Play()
function lerp(a, b, t)
return a * (1-t) + (b*t)
end
local prePlaybackLoud = 0
local postPlaybackLoud = 0
spawn(function()
while wait() do
prePlaybackLoud = script.Parent.PlaybackLoudness
wait(1)
postPlaybackLoud = script.Parent.PlaybackLoudness
end
end)
spawn(function()
while wait() do
local ppL = prePlaybackLoud
local pPL = postPlaybackLoud
for i = 0,1,.01 do
wait()
workspace.SoundPart.PointLight.Range = lerp(prePlaybackLoud/25, postPlaybackLoud/25, i)
end
end
end)
It seems to update 2 seconds late and it runs the lerp on the second before in the song. This was my final attempt before writing this question.
GOAL: I want to learn how to smoothly visualize audio on the range of a point light.

1 comment
I think a moving average of the PlaybackLoudness produces better results (and is waaay less complicated) than tweening.