Game's performance decreases overtime

(Not sure if this is in the right category as I was originally going to place this in #help-and-feedback:scripting-support)

Two friends and I made a randomizer fighting game until we started to noticed a critical bug that we can’t figure out the core root to. The game’s performance slowly starts to drop the longer you play, causing most weapons to be almost practically useless or game-breaking. A good example of this would be an item called michael p -which damages all humanoids that’s in range of the item-. When the game’s performance starts to drop, the DPS of the tool starts to decrease until its doesn’t even damage. We also noticed how the game’s performance drop speed changed depending on how many players are there, which makes it insanely hard / time consuming to replicate/recreate without many players. When there was a 15 player server, the game’s performance was dropping massively, unlike having a server with 5 players in it.

I noted down what the performance drop does to the game:

  • All serversided functions such as wait() becomes delayed making scripts last longer than its suppose to or desynchronize scripts.
  • Performance decrease does not affect ping, so if you have ~40ms and you use a basic melee, there should be no delay between the click.
  • Weapon cooldowns are extended, causing the game to feel way slower.

We had some ideas on what could be the root cause such as:

  • DataSaves causing lag every time a player joins the server. (Recently rewrote the data system, so that shouldn’t be the issue)
  • Possibly too many loops (Did some looking around on hopefully other devforum posts and some claim that having too many loops can cause server issues)?
  • Server possibly can’t handle much.
  • Possible memory leak?
  • Projectiles probably scuffed?
  • Connections cause lag / Too many Connections not disconnected?
  • The amount of players might be too much for the game to handle.

I’m not fully sure what’s causing it, but if anyone might have an idea and would like to say what they think could possibly be causing the performance drops, then don’t hesitate to give your idea. I’ll gladly appreciate any ideas. Thanks you.

EDIT: I can most likely confirm it’s caused from a memory leakage.

1 Like

I had this same error with my game too. Do you have any clone scripts in your game? I did with my rockets in my game and some of the parts didn’t get deleted also check how many joints and welds your game has and how many physics affected objects you have in workspace as this can critically harm your game performance.

You should avoid using wait(). Something like wait(1) is better, though too many of them can cause them to take longer than expected. You can use game:GetService("RunService").Heartbeat:Wait() instead (note you should probably store game:GetService("RunService") in a variable).


You game could also be leaking memory. Remember to disconnect connections, put variables in proper scope, and remove unnecessary references to data.
1 Like

The game rarely uses welds except for certain models. The scripts that use clone() is mostly ranged weapons and a character setup system that’s used to rig the character and insert requirements into the character.

I’ll take consideration with wait() and experiment with Heartbeat. The memory leakage could theoretically be a reason to, so I’ll also take your word for it, although I’m not fully sure if the memory would increase if there’s too many connections as the last time I checked, I somehow had roughly the same memory as if I joined a regular server. Maybe I might’ve looked incorrectly or something else, but I’ll keep both things you said and experiment with Heartbeat. Thank you.

1 Like