local runS = game:GetService("RunService")
local numBars = 30
local barWidth = 2
local thickness = 5
local visualizer = Instance.new("Model")
local visualizerPosition = Vector3.new(0,0,0)
local startingPosition = visualizerPosition - Vector3.new((numBars+barWidth)/2 - barWidth/2, 0, 0)
for i = 0, numBars - 1, 1 do
local b = Instance.new("Part")
b.CanCollide = false
b.Anchored = true
b.Size = Vector3.new(barWidth, 1, thickness)
b.Position = startingPosition + Vector3.new(i*barWidth, 0, 0)
b.Material = Enum.Material.Neon
b.Parent = visualizer
end
visualizer.Parent = workspace
local musicValue = script:WaitForChild("Music")
local function updateVisualizer(dt)
local l = musicValue.Value.PlaybackLoudness * .075
for i, bar in pairs(visualizer:GetChildren()) do
bar.Size = bar.Size:Lerp(Vector3.new(bar.Size.X, l * (math.random(0,100)/100), bar.Size.Z), 1-(.01)^dt) -- this line
end
end
runS.Heartbeat:Connect(updateVisualizer())
It looks like there is an issue with the line 1-(.01)^dt . It seems that dt is nil , so when it is raised to the power of .01 , it results in nil . This is causing an error when trying to perform arithmetic with nil .
One possible solution would be to check if dt is nil before trying to perform the arithmetic operation. You could do this by adding an if statement to check if dt is nil , and if it is, assign it a default value.
Here is an example of how you could modify the code:
if dt == nil then
dt = 1
end
bar.Size = bar.Size:Lerp(Vector3.new(bar.Size.X, l * (math.random(0,100)/100), bar.Size.Z), 1-(.01)^dt)
This will assign dt a default value of 1 if it is nil , which should allow the code to run without error.
I generated this response with https://chat.openai.com/chat, let me know if you have any further questions and I’ll give the AI that. Note that sometimes the code it generates is wrong and some manual fixing has to be done. I haven’t tested this now but from my eye it looks correct.
It is not possible to perform arithmetic on a number and nil because nil is not a valid value for performing arithmetic operations. If there is an attempt to do so, it will result in an error. In the given code, it is not clear where nil is being used or attempted to be used in the arithmetic operation.