After server is up for around an hour lag is visible

After any server is up for around an hour the mobs start to lag and projectilles casted begin to lag and slow down as well. Once a server is like this it stays like that and this only seem to happen in old servers. I just want to know what I should to to make sure my game has servers that can be played for hours at a time without lagging.


Are more parts and scripts running throughout the game’s run time? Maybe consider Debris to clean up unused/old items.


All of the projectilles are cleaned up after a few seconds and stuff but after a certain amount of time everything starts moving in slow motion. Like if you’ve ever seen a roblox rocket or part move in a laggy server and its like in zero gravity. thats what happens to my game. I do use some while true do scripts though. Here is one of the scripts in the game to spawn a slime. -

If you could let me know if this is a good or bad script and if it would or wouldnt cause lag that would be great.

Honestly, I’m not sure if that script would cause lag. However, I do know that the Roblox physics engine moving in slow motion is due to lots of calculations (moving parts). Are projectiles being destroyed?

Also, if you don’t use said projectiles, does the hame still lag after a certain amount of time?

No I wouldnt say so. I’ll show you a script of a ability that makes a projectille and you can see whats going on.

Note that the projectille has a script in it that automatically destroys it after a few seconds.

Try print() right before the projectile is destroyed to confirm that the destroying is running. If not that, then I have no idea what could be causing it.

Roblox still lags if you have a lot of welds or the mobs are very detailed, there are unanchored parts just going crazy. You should look into tools that show server data usage and try to find the origin.

Yea the mobs arent too detailed its just some slime enemies. Also remember everything works fine for the first like hour the game only starts breaking after the server is around 1 hour in age.

Please use code tags, images of code are not a helpful format for anyone trying to help.


I also dont understand why sometimes the usage is fine example:

Put then other times the usage is at like 800 or 900 MB. Im currently in a server with a timer on and im gonna see how long it takes for the server to start glitching out and try and find the issue in real time.

I stayed in this server for two hours and this is what the memory usage was after 2 hours .
is this good?

1 Like

memory leak. look for binded events that are never disconnected.

You’re destroying the sound, but not the projectile.
Make sure you call proj:Destroy().

Additionally you can try running the game in studio for a while and then look in the workspace for lingering parts.

Memory leaks don’t usually cause performance issues (lag), but they cause crashes.

There is a despawn script in the projectille that automatically destroys it after a few seconds.

I’m not that educated about the garbage collection system in Roblox’s Luau, but I’m pretty sure that the server still holds a “reference” to that projectile. Try destroying it without the use of the despawn script.

Also, a “reference” to an object is like, having multiple scripts have a variable that leads to the same instance. For example, if 2 scripts have a variable called “Rocket” that is actually the rocket model, and one of the scripts sets that variable to nil, then the other script will still have that rocket.
If both scripts set their “Rocket” variable to nil, Roblox will automatically detect it and get rid of the “reference” entirely, because there are no scripts that have the rocket model saved in them.

If anybody here knows better than I do, please correct me if I’m wrong.

Alternatively, you could set the proj variable to nil in the server script… I think

Why the destroy script? From an outsider perspective, the Debris service does the same job, but guarantees that the instance will be destroyed after the amount of time given.

How are you destroying the projectile? Have you tried using DebrisService?

Debris | Documentation - Roblox Creator Hub

At least using this will farm out Instance destruction to Roblox’s inbuilt handler.