Excessive lag issues

I’ve been hard at work programming a Clans and Guides fort for about a couple months now, and it’s been going great, until recently. As I put the finishing touches on it, and we began lots of testing, one thing we noticed was that it lagged. Not just you know “oh a spike here, a spike there”. It got worse.

Place

Outpost Blanc DEV EDITION - Roblox

Usually when we test it, this game has an upwards of 16 people in it at once, sometimes more. A game of 16 people in my opinion is not a lot, since roblox servers can now support 100. When you first join the game, it’s pretty stable, no issues and no lag. You get your 60 fps that roblox caps you at.

However, flash forward, as most C&G forts have, a “start” command. This effectively distributes weapons, activates a timer, and anything else tied to it. Some lag is to be expected during this period. As expected, there is some lag. Most players don’t go lower than 50 fps at this point. I can live with some lag like that.

However, most “matches” in this game last 25 minutes or longer, and typically about 5 minutes in, players start noticing extreme lag (Including myself). Let me make clear, it’s not a sudden spike, it’s a gradual increase in lag. Frames slowly start going down, and typically at the end of 25 minutes even, players are running at 25 or less fps. Imagine how slow this gets when we’re running 45 minute matches.

I’ve been looking at the f9 console, and there aren’t too many errors that cause it, and a lot are resolved due to player death immediately after. One thing that is note worthy is in the “script” tab under “rates”, one of my scripts has over 1000 rate. I don’t entirely know what this means, or where to look to find sources of lag. I read somewhere that using spawn(function() would cause lag, so I cut a number of those out of my game as well.

Help would be appreciated!

Note, if you’re in need of data to assist me, I will not be able to provide it instantly, as I will need to get 18 or more players, and we will need to play the game for 25 minutes.

Data I have right now is to this extent: (I have changed some scripts since and made changes)


I appreciate any help you can offer in the meantime to make this less laggy and more enjoyable for players!

1 Like

1 of 2 things I can come up with off the top of my head are:

  • Excessive amount of loops running in your scripts
  • Not an excessive amount of loops, but nothing to break those loops so they continue to run indefinitely.

I’m more than positive there are other things going on as well, but the 2 things I’ve listed above are somethings you may consider looking into.

I will look into this. I can confirm that there is a minimum of 2 loops running, so this could be an issue.

Would it be bad to have untracked memory on the server side?


I don’t entirely know what this means either, so could just a little bit of untracked memory cause some lag?

Having untracked memory isn’t the worst thing.

1st, take into account that Roblox is undergoing maintenance issues the past couple days.
2nd, look at other loops that could be running when the player is added to the game. The connections may not be closing or you may have indefinite loops running on code such as:

game:GetService('Players').PlayerAdded:Connect(function(Player)

I would also check to make sure you’re closing all connections after certain events are done with, certain conditions are met, or events are completed.

So I made some changes. The way I handled UI updating previously was a loop on a local script that sends a remote function to the server. Said remote function would request UI data to update the UI. I decided it’d be more efficient to just push a separate remote from the server to the client instead for more uniform performance and less requests to the server. It fixed a lot of the issues, but there was still noticeable lag near the end of a 45 minute game, but 25 minutes in there was near no lag.

Look into memory usage, gradual lag like this is very often caused by memory leaks.

When looking at my code what are some pointers for identifying memory leaks.
What might a memory leak in some code look like?

There are tons of resources on this forum that deal with discussions on memory leaks, I suggest you search and read through them if you haven’t before.
In my experience connections that are not explicitly disconnected or destroyed and reference some other memory are usually the culprits (or lingering instances in the game workspace, but this is rarer since it is much more easily identified).
This thread explains some potential memory leaks in great detail: PSA: Connections can memory leak Instances!

1 Like