My game gets laggy when im alive for too long

I’m making a parkour zombie game similar to dying light, and I noticed when testing in studio and playing it outside of studio that if I’m alive for too long the game starts to get really laggy and I need to reset.

The game features many scripts but all my attempts to find the issue simply didn’t work, I tried waiting until the game was laggy and going through each object to see if there was any constantly duplicating instances but that was useless and I can’t think of any other reason for why this is happening.

The game has a large emphasis on staying alive, and needing to die every 10 minutes because of lag completely undermines that.

2 Likes

you can try using moudles or combining multiple scripts (if they are in ServerScriptService)

1 Like

It could be because of a loop, connected to the heartbeat or just a while wait() type thing, try limit looping if you can as it strains the server.

1 Like

If the FPS is the problem then you have a memory leak, this can happen if you leave connections like heartbeat or UI connections active after their not needed, because they are not broken they continue to detect input / run the loop indefinitely

3 Likes

Using a single script or modules isn’t inherently better than having multiple scripts. It’s simply a different method for code organization.

3 Likes

Since it’s fixed by resetting, it seems to me like the problem stems from code related to the player character. Are the performance issues on the client, the server, or both? Do you have any scripts running inside the character model?

2 Likes

The lag seems to be completely on the client

2 Likes

i have a few heartbeat loops but when i removed them i still got laggy

2 Likes

What about normal loops in LocalScripts, most likely ones in the StarterPack or Backpack as it fixes once you reset.

2 Likes

i have one wait loop for footsteps thats rather unnecessary, i think i’ll try removing that and seeing if that fixes the issue

So that turned out to be the issue, i removed the loop and now the entire issue is completely gone