My game is getting slower over time

At first, the game is completely normal, but when people keep staying in the server and after 1 or 2 hours, the game starts getting slower.

I have tried many research like disconneting every connect when player leaves, try not to have too many parts, etc. But it doesn’t work

My game is a PvE type so sometimes it DOES spawn a lot of parts but I have used Debris Service to destroy them, and all of the vfx will be in client

Is there anything else I can do to stop this circumstance ?

1 Like

You need to use the profiling tools to see what is consuming time, which unfortunately I’m not very good at. A really easy way to slow a game like this is to have too many threads, though. Is there any mechanism which adds/copies scripts in your game? Or anywhere task.spawn can be called?

there is only one mechanism which copies scripts in my game for now, but I am very sure that the script will be deleted once it is done being used, task.spawn(), I used it a lot as well as task.wait()

I was doing some more researchs, maybe it is because I am using Debris Service ?

You should add some code to track each time a script is created and destroyed and print a count, if it keeps going up, then there’s a problem. You can make a counter for this using a module script.

1 Like

I will do it but I don’t really think this is the main problem, the script which copies this script is an event script, it only has 25% chance to copy for the event, so there was a server WHICH the event never happended in but it is still getting laggy over time

You will need to use the profiler then. There’s not many other ways to figure out what it is.

I will try, should I try to clear all of the table when it is done and not used any more ? Like when the battle ends, should I table.clear it ?

What table are you talking about?

the table which stores player informations

I have no idea if that would matter without knowing much more about what you’re doing with that. You shouldn’t have tables that could grow in size with no limit, but the profiler will tell you that in the form of memory.

Look at micro profiler
Ctrl+F6 then pause it on Ctrl+P and look what causes lags
It is likelly data being memory leaked and being unable to get gced

2 Likes

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