Issues with getting bass from AudioAnalyzer:GetSpectrum()

What I am trying to do is link spotlights to certain pins on the Spectrum and make them behave differently from others, think of it like a festival when there is a bear the lights go on.

This is what I got

--[[
    This script makes all lights in Workspace/Lights react to audio spectrum.
    - Flickers light brightness based on bass (spectrum[1])
--]]

local AnalyzerFolder = workspace:WaitForChild("AudioAnalyzer")
local PlayerPart = AnalyzerFolder:WaitForChild("PlayerPart")

local AudioPlayer = PlayerPart:WaitForChild('AudioPlayer')

-- Find the AnalyzerPart and AudioAnalyzer
local AnalyzerPart = AnalyzerFolder:WaitForChild("AnalyzerPart")
local Analyzer = nil
if AnalyzerPart then
	Analyzer = AnalyzerPart:WaitForChild("AudioAnalyzer")
end
if not Analyzer then
	warn("AudioAnalyzer not found")
	return
end

-- Find all lights in the Workspace/Lights folder
local LightsFolder = workspace:FindFirstChild("Lights")

-- Helper: Recursively find all Light objects in a given instance
local function getAllLights(parent)
	local lights = {}
	for _, child in parent:GetDescendants() do
		if child:IsA("PointLight") or child:IsA("SpotLight") or child:IsA("SurfaceLight") then
			table.insert(lights, child)
		end
	end
	return lights
end

local bassBins = {1, 2}

local function getBassValue(spectrum)
	local sum = 0
	for _, i in ipairs(bassBins) do
		if spectrum[i] then
			sum = sum + spectrum[i]
		end
	end
	return sum / #bassBins
end

-- Gather all lights in the Lights folder
local allLights = getAllLights(LightsFolder)

AudioPlayer:Play()

---- Pulse settings
local minBrightness = 6
local maxBrightness = 12

-- Beat detection parameters
local beatThreshold = 0.1  -- start lower to catch smaller beats
local beatCooldown = 0.3
local lastBeatTime = 0

local function isBeat(bassValue)
	local currentTime = tick()
	if bassValue > beatThreshold and (currentTime - lastBeatTime) > beatCooldown then
		lastBeatTime = currentTime
		return true
	end
	return false
end

local pulseDuration = 0.15  -- how long the beat flash lasts
local pulseIntensity = 1.5  -- multiplier for brightness on beat

local pulseEndTime = 0
local baseBrightness = minBrightness

while true do
	task.wait(0.05)
	local spectrum = Analyzer:GetSpectrum()
	if spectrum and #spectrum > 0 then
		local bass = getBassValue(spectrum)

		-- Normalize and scale bass value for brightness
		local scaleFactor = 10
		local adjustedBass = math.clamp(bass * scaleFactor, 0, 1)
		baseBrightness = minBrightness + (maxBrightness - minBrightness) * adjustedBass

		-- If beat detected, start pulse
		if isBeat(bass) then
			pulseEndTime = tick() + pulseDuration
		end

		-- Calculate current brightness:
		local currentTime = tick()
		local brightness = baseBrightness

		if currentTime < pulseEndTime then
			-- Calculate how far into the pulse we are (0 to 1)
			local pulseProgress = (pulseEndTime - currentTime) / pulseDuration
			-- Pulse brightness peaks at pulseIntensity and fades out
			brightness = math.clamp(baseBrightness * (1 + (pulseIntensity - 1) * pulseProgress), minBrightness, maxBrightness * pulseIntensity)
		end

		-- Apply brightness to all lights
		for _, light in pairs(allLights) do
			light.Brightness = brightness
		end
	end
end

If nothing is happening at all, a few important questions first:

  1. Do you have a Wire instance linking the AudioPlayer (source) to AudioAnalyzer (target)?
  2. Is this code in a LocalScript or Script with RunContext.Client? (no audio on server)?
  3. Is the AudioAnalyzer window size set to Medium? If it’s set to Large, bins 1 and 2 would be too low frequency to pick up most beats.

If there is something happening, just not exactly what you expect, can you explain how far you’ve gotten as what the issues are?