My game get laggier the more I play?

Hi! I have a simulator saber type game and i was afk in it for about 1 hour opening eggs. I noticed that the game got increasingly more lagged than before i had afk. How do i fix this?

This is in public game btw not studios

You probably have a memory leak. In this case, you might have a connection thats doesn’t disconnect or you have a virus.

1 Like

That can be some Reasons

  1. Server Side
    Hey, check if you have a problem, if so, maybe it can be server side or something press Ctrl - Shift - F and Find"require(" if the result will show something maybe that Serverside, if that Server side Click on the result and delete it

  2. Spread or Fire
    if that Spread or Fire that can be another virus you need to find in the Roblox Studio Explorer Search bar “Fire” or “Spread” after it if that show result delete it

Plus if that a lot spread or fire, Also I can create script that delete it

Hi, I’ve went to all the module scripts and scripts and I have found no backdoor viruses or anything. i think it may be potentially not disconnecting connections but I have made sure that in my scripts there is always a disconnect() when a connection is not needed anymore but I may have missed a few. Are there any other possible reason?

You said you are opening eggs, so I think it might have something to do with the animation when you open it. Go check to see if your have anything that was not disconnected.

well this is the egg egg animation script, I think I have disconnected all connections and stuff


function eggHandler:TweenEgg(eggName, code)
	plrGui.Main.Enabled = false
	plrGui.EggBillboard.Enabled = false
	if code == "One" then		
		local eggClone = self:GetEggModel(eggName):Clone()
		local root = weldEgg(eggClone)
		root.Parent = workspace

		local pos = Instance.new("CFrameValue")
		local heartbeatFunc = runService.RenderStepped:Connect(function(dt)
			local tween = tweenService:Create(eggClone.PrimaryPart, TweenInfo.new(0.01), {CFrame = workspace.CurrentCamera.CFrame * pos.Value})
			tween:Play()
			tween.Completed:Wait()
			tween:Destroy()
			tween = nil
		end)
		pos.Value = CFrame.new(0,0,0)
		
		local tween = tweenService:Create(pos, TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.Out), {Value = CFrame.new(Vector3.new(0,0,-10))})
		tween:Play()
		tween.Completed:Wait()
		tween:Destroy()
		tween = nil
		
		local firstNum, num, len, size = 0, 0, 1 * ((1 - upgradeFolder.IncreasedEggOpeningSpeed.Value / 10) / returnTwoForGamepass(plr)), 30
		local originalVolume = sounds.Whoosh.Volume
		
		repeat
			wait(len)
			num += 1
			if num == 3 then
				num = 1
			end
			local value = CFrame.Angles(0, 0, math.rad(size * (num == 1 and 1 or -1))) -- * CFrame.new(Vector3.new(0,0,-10))
			local tween = tweenService:Create(pos, TweenInfo.new(len, Enum.EasingStyle.Sine, Enum.EasingDirection.Out), {Value = value * CFrame.new(Vector3.new(0,0,-10))})
			tween:Play()
			sounds.Whoosh:Play()
			sounds.Whoosh.Volume *= 0.8
			local compTween
			compTween = tween.Completed:Connect(function()
				tween:Destroy()
				compTween:Disconnect()
				tween = nil
				compTween = nil
			end)
			len *= 0.8
			size *= 0.8
		until
		len <= 0.01
		eggClone:Destroy()
		eggClone = nil
		heartbeatFunc:Disconnect()
		heartbeatFunc = nil
		sounds.Whoosh.Volume = originalVolume
	elseif code == "Triple" then
		local done1, done2, done3 = false, false, false
		for i = 1, 3 do
			spawn(function()
				local eggClone = self:GetEggModel(eggName):Clone()
				local root = weldEgg(eggClone)
				root.Parent = workspace
				
				local offSet
				if i == 1 then
					offSet = Vector3.new(-7,0,0)
				elseif i == 2 then
					offSet = Vector3.new(0,0,0)
				elseif i == 3 then
					offSet = Vector3.new(7,0,0)
				end

				local pos = Instance.new("CFrameValue")
				local heartbeatFunc = runService.RenderStepped:Connect(function(dt)
					local tween = tweenService:Create(eggClone.PrimaryPart, TweenInfo.new(0.01), {CFrame = workspace.CurrentCamera.CFrame * pos.Value})
					tween:Play()
					tween.Completed:Wait()
					tween:Destroy()
					tween = nil
				end)
				pos.Value = CFrame.new(0,0,0)
				
				local tween = tweenService:Create(pos, TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.Out), {Value = CFrame.new(Vector3.new(0,0,-10)) + offSet})
				tween:Play()
				tween.Completed:Wait()
				tween:Destroy()
				tween = nil
				
				

				local firstNum, num, len, size = 0, 0, 1 * ((1 - upgradeFolder.IncreasedEggOpeningSpeed.Value / 10) / returnTwoForGamepass(plr)), 30
				local originalVolume = sounds.Whoosh.Volume
				
				if gamepassHandler:PlayerHasGamepass(plr, 20085937) then
					len /= 2
				end
				repeat
					wait(len)
					num += 1
					if num == 3 then
						num = 1
					end
					local value = CFrame.Angles(0, 0, math.rad(size * (num == 1 and 1 or -1)))
					local tween = tweenService:Create(pos, TweenInfo.new(len, Enum.EasingStyle.Sine, Enum.EasingDirection.Out), {Value = value + Vector3.new(0,0,-10) + offSet})
					tween:Play()
					if i == 1 then
						sounds.Whoosh:Play()
						sounds.Whoosh.Volume *= 0.8
					end
					local compTween
					compTween = tween.Completed:Connect(function()
						tween:Destroy()
						compTween:Disconnect()
						tween = nil
						compTween = nil
					end)
					len *= 0.8
					size *= 0.8
				until
				len <= 0.01
				eggClone:Destroy()
				eggClone = nil
				heartbeatFunc:Disconnect()
				heartbeatFunc = nil
				sounds.Whoosh.Volume = originalVolume
				if i == 1 then
					done1 = true
				elseif i == 2 then
					done2 = true
				elseif i == 3 then
					done3 = true
				end
				return
			end)
		end
		repeat wait(0.1) until done1 == true and done2 == true and done3 == true
		done1 = nil
		done2 = nil
		done3 = nil
	end
end

Oh I just realised I never destroyed the pos CFrame Value. This might be the reason why

That may be very stupid to say that but your PC might be a bit overloaded or overheating due to the work that provided Roblox to the computer. Is this happening to all players ?

Hi, yes it is happening to all players and I think I might have found the problem. I will check back in an hour to see if it still lags or not.

1 Like

You can’t use wait() in renderstepped (to my knowledge) because it will just run every frame so your playing the tween a ton.

Yep, RunService will run every frame despite the :Wait()

I know that but that’s not the thing that’s causing the memory leak because I am destroying all instances and connections of that tween. The source of the problem is the pos Value I think where I’m not deleting it.

Yet, what I’m saying is that it may not be a memory leak and it could just be that you overloading the devices with too many tweens.