-- RENDER LOOP --

local MPL,PL,curr=0 curr=Sound.SoundId
game:GetService'RunService'.RenderStepped:connect(function()
	PL=Sound.PlaybackLoudness
	if Sound.IsPlaying and PL==PL then -- Sound is playing & PlaybackLoudness is not undefined
		if curr~=Sound.SoundId then MPL=0 -- Reset the relative Max PlaybackLoudness on song change
			curr=Sound.SoundId
		end
		MPL=math.max(PL,MPL) PL=PL/MPL -- Normalize PL based on relative Max PlaybackLoudness
		if PL==PL then
			Set(math.floor(PL*nBars),PL*Height) -- Modify bar relative to PlaybackLoudness
		end
	end
end)
while wait() do
	script.Activator.Value = not script.Activator.Value
end
