Help optimizing

each server full of people averagely uses 2000-3000 mb

i’ve been trying to optimize for a long back and reduced all the while loops that never end from ~30 all the way down to 1 on the server

looking in the memory usage i found these that i have no idea how to reduce at the same time very high:


animation uses 200 mb

physicsparts uses 500-600 mb (i set a lot of parts network ownership idk why its so high)

the map is relatively large but never creates server lag without scripts so it can’t be the amount of parts in the map

just looking for responses that could be slowing down games like not disconnecting functions or a large amount of while loops

The main things that used to cause lag in my games were while true do loops and high mesh/voxel count.

You can easily fix the infinite loops by playing wait() in the middle: while wait() do
I also trimmed a bit of terrain off the bottom of the map and reduced the amount of meshes to fix the high voxel and mesh count.

This fixes a loop that almost everytime should be replaced by listening to events for example. Then the code runs only when it should be instead of checking. This drastically improves a performance. I say it because the next step of using while wait() do is the repeat wait() until that has no sense at all and it’s laggy. Why should you use repeat wait() until player.Character when you can use player.CharacterAdded:Wait() as a yield or player.CharacterAdded:Connect(function()...

Even if someone don’t cares about that still should place wait() inside a loop.
Putting a wait() insted of true is a bad habbit that is well described here.

Roblox made an article about Improving Game Performance.