Hello, I have a visualizer script that changes the color of a part depending on the loudness of the music. The problem is, is that if I try to use it with the ambience color lighting, it stays at 0,00 and doesn’t lerp to the second color, vice versa first. I’ve haven’t tried anything else since I literally have no idea why it doesn’t work.
local Color1 = Color3.fromRGB(0, 0, 0)
local Color2 = Color3.fromRGB(203, 235, 255)
-- [0 -> 1]. if 0, the beat won't go down, if 1, it will follow it without smoothing
local beatDownAggressiveness = 0.1
-- [0 -> 1]. if 0, the beat won't go up, if 1, it will follow it without smoothing
local beatUpAggressiveness = 0.9
local function lerp(a, b, t)
return a + (b-a)*t
end
function inverseLerp(a, b, x)
return math.clamp((x-a)/(b-a), 0, 1)
end
local lastT = 0
RunService.Heartbeat:Connect(function(deltaTime)
if on == true then
local t = inverseLerp(0, 300, Sound.PlaybackLoudness)
if t >= lastT then
t = lerp(lastT, t, beatUpAggressiveness)
local change = Color1:Lerp(Color2, t)
ambience = change
else
t = lerp(lastT, t, beatDownAggressiveness)
local change = Color1:Lerp(Color2, t)
ambience = change
end
lastT = t
end
end)