Lag Slowly Accumaltes

Good Morning!

So Im making an RNG and the ping slowly builds up, so like after 5 mins its un playable.

Im thinking its the Client Memory Usage but im not sure. Btw it happens to everyone whether they have a super good pc or just a phone.

Thank You!

I’m guessing you have a memory leak. Do you have any nested functions in your game?

only a few but most of them are in module scripts. Do you think that will be the cause

so, inside the modulescripts, for example do you do this

function module.idk()
property:getpropertychangedsignal:connect(fucntion()
--do something
end
end 

if you called that it would multiply which is probably wayht is going on with the function s you have in your modules

Yes so in one of my stats scripts i do that with a lot of remote event functions like this

local function Name()
      RS.Increase.OnServerEvent:Connect(function()
           ("Hello")
      end)
end

Written From memory but hope it portrays what the script is like

yeah that is a memory leak, you’re not cleaning up the connection and there is no way to access it so it just sits in memory and uses useless space, on top of that, it will be reconnected every time you call the function, so more events will pop up and sit there.

to fix this, keep a reference to the event to clean it up later:

local myeventref = nil
local function name()
  if myeventref then myeventref:Disconnect() myeventref = nil end--reset the variable to clean up the connection
  myeventref = RS.Increase.OnServerEvent:Connect(function()--connect and assign.
    print ("hello");
  end)
end

something like that, if you need multiple use an array, but whatever you do, make sure the connection is cleaned up.

hope this helps!

Not sure is this is the solution but Suphi has a video on remote functions.
(he also has other great scripting vids)
RemoteFunction - Roblox Scripting Tutorial

Store the connection in the table that the module returns so no race conditions happen.