How to lower lag spikes and memory usage

Hi, so I made a similar post yesterday but I did not get any valid answers so I am rewording my question to be more specific. I was play testing my game then it just suddenly got lag spikes every 1 - 2 seconds. I didn’t know where it was coming from. I check script performance and i found a script over 3% activity. I altered the code a bit and it is now 0.1 - 0.3% activity. However, the lag spikes did not disappear. In addition to these lag spikes, I also found out that tweening the size property of an object caused it to lag a lot for some reason. Also, memory is quite high at around 1.6k to 1.8k in studio and 1.2k - 1.4k in real game. Please help

1 Like

Do you have other apps open? If yes then close them and check memory again.

1 Like

I only had discord and spotify open. I closed them and it is still very high memoryimage

1 Like

I’m sure unions and negates can create lag. Do you have any unions, negates or parts that aren’t necessarily needed?

1 Like

There are only 8 union parts in the whole map. Most of the map is either base parts or mesh parts. It is a saber simulator game btw

1 Like

Ok then. Do you know how many parts are in those unions?

1 Like

I do not think it has anything to with the map because it just suddenly started to lag and it has something to do with the scripts I think. To answer you question, the unions have around 8 - 15 parts in them

1 Like

That is a little much. Could it be your internet connection?

1 Like

If you think it has something to do with your scripts then I would recommend trying to incense it and get rid of any unnecessary code.

1 Like

My wifi is fine. I had tons of scripts before the lag and it did not lag. I didn’t even edit any scripts it just lagged for no reason and tweening just became really laggy.
image

1 Like

Ok do you know what you changed or added that may have made it start lagging?

1 Like

A particular script or part maybe.

1 Like

I made a mutation script for pets. I disabled that script but still lag spikes and 2000 memory. Other than that script that’s about it.

1 Like

Ok then I’m out of advice. All I can say is to keep an eye on your scripts and to research on the web. Sorry I was unable to solve your problem.

One of the best and most simple ways to fix lag in game is “Streaming Enabled.”
Turning streaming enabled on will render parts in and out in game to help with lag.
Heres a post about it
https://developer.roblox.com/en-us/api-reference/property/Workspace/StreamingEnabled

I fixed the lag. Turns out there was a humanoid in the workspace which made it lag somehow. Thank you for everyone who contributed on this post!