Everytime this function is run, The memory increses

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Guns

  2. What is the issue? Every time i shoot, It increases the place script memory by 0.02, Which I am quite sure that I already put everything in the debris service, And it seemed that this script is the cause, As all the other script dont leak and the raycast module I am using, Does not increase it’s memory upon shooting, Even when I set every varieble i see to nil once it has reached a dead end, It still increases

game.ReplicatedStorage.Remotes.Weapons.Bullet.Shoot.OnServerEvent:Connect(function(plr,mousehit,config)
	do
		if not game.Players:FindFirstChild(plr.Name) then print("NOPLAYER") return end
		if not plr.Character then print("NOCHARS") return end
		if not plr.Character.Head then print("NOHEAD") return end


		local PenetrateVar = config.bulletConfig.penetration.maxPenetration
		local lastPos = plr.Character.Head.Position
		local dir = (mousehit-plr.Character.Head.Position).Unit
		local dirCF = CFrame.new(mousehit) + dir * 500

		local shell = game.ServerStorage.Shells:FindFirstChild(config.bulletConfig.SubType):Clone()

		shell:PivotTo(plr.Character:FindFirstChildOfClass("Model").Hull.Shell.WorldCFrame)
		shell.AssemblyLinearVelocity = (plr.Character:FindFirstChildOfClass("Model").Hull.Shell.WorldCFrame.UpVector*-10)
		shell.Parent = workspace
		game.Debris:AddItem(shell,3)
		for count = 1,10 do
			local result =Silencer_Cast.FastCast(plr,lastPos,dir,500)
			if not result then return end

			if result.Instance.Parent:FindFirstChildOfClass("Humanoid") then
				result.Instance.Parent:FindFirstChildOfClass("Humanoid").Health = result.Instance.Parent:FindFirstChildOfClass("Humanoid").Health - 10
			end
			if result.Instance.Transparency > 0 then
				local clne = script["Bullet Glass 4 (SFX)"]:Clone()
				clne.Parent = result.Instance
				clne:Play()
				game.Debris:AddItem(result.Instance,0.753/0.7)
			end
			local distance = Silencer_Cast.getIntersectionLength(result.Instance.CFrame,result.Instance.Size,plr.Character.Head.Position,dirCF.Position	)
			if distance >= PenetrateVar then
				local a = Instance.new("Attachment")
				a.WorldPosition = result.Position
				a.Parent = workspace.Terrain
				local a2 = Instance.new("Attachment")
				a2.WorldPosition = plr.Character:FindFirstChildOfClass("Model").Hull.ShootPoint.WorldPosition
				a2.Parent = workspace.Terrain
				local beam = script.Beam:Clone()
				beam.Attachment0 = a2
				beam.Attachment1 = a
				beam.Parent = plr.Character
				local l = script.PointLight:Clone()
				l.Parent = plr.Character:FindFirstChildOfClass("Model").Hull.ShootPoint
				game.Debris:AddItem(beam,0.1)
				game.Debris:AddItem(a,0.1)
				game.Debris:AddItem(l,0.1)
				game.Debris:AddItem(a2,0.1)
				return
			end

			lastPos = CFrame.new(result.Position) + dir * distance
			lastPos = lastPos.Position
			PenetrateVar -= distance
		end
	end
end)

One question it seems you are destroying the result Instance, shouldn’t you be destroying the sound instance?

Or use the Sound play on remove property?

https://developer.roblox.com/en-us/api-reference/property/Sound/PlayOnRemove

Ill try but since i parent the sound to the part that’s going to be destroyed, I expect it to be destroyed as well

It still increases, As an information, That’s a server script, And I’ve pinpoint the leak to the script

Don’t use debris service there is a better version of that: PartCache - Open Source - Roblox

Turn out roblox garbage collect when memory increases to around 0.1 mb and every so often