Physics engine slowing down in my game

So yesterday, I was struggling to find a reason why my game was so slow. They told me different ways to solve the problem, and they worked, well, sort of. The slowing down occurred again and again later and I saw that the while loop that runs every 0.1 seconds is running at 0.11, 0.12, 0.13, 0.14, etc. I was so confused why, so I decided to add the physics engine framerate into the debugging. It showed that the frame rate of the physics engine slowly turned from 60 (usual) to 53 to 45 to 32 to 13, and right now it’s at 8 frames per second. If you’re wondering, everything is normal except the fact that interacting with things has a bad delay.


The left side is the absolute wait time for wait(0.1), and the right is the frame rate of the physics engine. If you’re wondering, this only occurs when you have multiple people in the same server (max is 4). Why does this happen? What can cause the physics frame rate to slow down?

2 Likes

It appears that something must be cloning a part or model or something like that alot. Use the Find/Replace All tool to find the line :Clone() in all of your scripts. One of them might be in a loop.

Generally this happens when there are loads moving parts or too many parts being generated, make sure that there isn’t a vast amount of parts being generated or something like that.

I checked the lines that clone objects but they are not in an infinite loop and are not being mass generated. Also the player’s framerate isn’t low, just the physics frame rate. Also people are moving just fine. It’s just the game thats responding slow and i checked the frame rate by doing the standard fps gui coding but replace renderstepped with heartbeat

1 Like

Try counting all of the unanchored parts while the game is lagging in the dev console:

n = 0
for i,v in next, workspace:GetDescendants() do
    if v:IsA("BasePart") then
        if v.Anchored == true then
            n = n + 1
        end
    end
end
print(n)

Update: I did more testing and it seems that it is not a memory leak and scripts are not being overloaded or anything

just ran a test doing that and it says i have about 350 unanchored parts but its most likely from this

I just ran another test that anchores everything but it only saves like 5 frames

image
Have you tried looking at the Shift+F4 menu to see if anything looked weird?
(Or any of the other menus like Shift+F1)

It shows that heartbeat is working fine but the fps debug thing i made uses heartbeat which is weird.