Camera script causing insane lag

Hi!

I’m having an issue with my camera script. It works fine, but it causes lag and piles up.
Thanks for any help!
Scroll part of my cam script:

			Mouse.WheelBackward:Connect(function()
				getCamPart().Position = getCamPart().Position + Vector3.new(0, .001, 0)
				game:GetService("TweenService"):Create(Camera, TweenInfo.new(0.05, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false, 0), {
					--orientation = CFrame.Angles(math.rad(0), RotR + RotL, math.rad(0)) * Camera.CFrame
					CFrame = getCamPart().CFrame
				}):Play()
			end)
			Mouse.WheelForward:Connect(function()
				getCamPart().Position = getCamPart().Position - Vector3.new(0, .001, 0)
				game:GetService("TweenService"):Create(Camera, TweenInfo.new(0.05, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false, 0), {
					--orientation = CFrame.Angles(math.rad(0), RotR + RotL, math.rad(0)) * Camera.CFrame
					CFrame = getCamPart().CFrame
				}):Play()
			end)

Video: (still processing rn, give it a minute)

Thanks!

How frequently is WheelBackward or WheelForward being called? You may have to limit the amount of times it may be called in a time frame. Scrollwheel input can exponentially grow depending on the hardware some players have (like an unlocked mouse wheel)

I have it running like this

game:GetService("RunService").RenderStepped:Connect(function(step)
	if not IsBuilding then return end
	if not getCamPart() then --WILL finish later
--more of my trash camera code
	while task.wait(0.05) do
--more hot garbage
if IsBuilding then
			Mouse.WheelBackward:Connect(function()
				getCamPart().Position = getCamPart().Position + Vector3.new(0, .001, 0)
				game:GetService("TweenService"):Create(Camera, TweenInfo.new(0.05, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false, 0), {
					--orientation = CFrame.Angles(math.rad(0), RotR + RotL, math.rad(0)) * Camera.CFrame
					CFrame = getCamPart().CFrame
				}):Play()
			end)
			Mouse.WheelForward:Connect(function()
				getCamPart().Position = getCamPart().Position - Vector3.new(0, .001, 0)
				game:GetService("TweenService"):Create(Camera, TweenInfo.new(0.05, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false, 0), {
					--orientation = CFrame.Angles(math.rad(0), RotR + RotL, math.rad(0)) * Camera.CFrame
					CFrame = getCamPart().CFrame
				}):Play()
			end)
			task.wait(0.05)
		end
	end
end)

ignore the ends and if statements, i kinda deleted random parts for that code

Kinda forgot this existed until I tested again, it’s still an issue.

Turns out it’s some sort of Memory leak…
image

If it’s a memory leak issue, could the connections be getting duplicated or connected more than once?

I dont think, the loop info is in an above post.