"RunService.RenderStepped:Connect(function()" Causing to low fps

Hi! I’m doing a system for my game.
I’ve used “RunService.RenderStepped:Connect(function()” in a function. It’s working nicely, but after a while game getting laggy. Is there a way I can fix this?

Looks like an memory leak, you keep creating new .RenderStepped events with BassHit() without clearing the previous events.

How can i remove or end the old renderstepped event?

You could store it in a variable outside your code

local Event
function BassHit()
	if Event then Event:Disconnect() end -- Disconnect old event
	Event = RunService.RenderStepped:Connect(function()
        [...]

however I suggest getting rid of this function entirely and relying on just 1 .RenderStepped so you don’t need to keep creating new / removing old events every time.

Thank you so much! Now it’s working correctly, and it’s not causing to low FPS.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.