Why does my game lag?

Hey there!

I just recently put some ads up for my game, and I have noticed that the servers are lagging.

Possible issues:

I could be parts and builds but I kinda doubt it because it only lags when there is a lot of people, 10+ after like 20 minutes.

I am guessing it has something to do with scripts.

I use a bunch of while loops

All pets use tween service

I thought I had fixed it before when I changed all my wait()s to wait(n(lowest is 0.05)) because I heard that would be an issue and it made sense, now I see it still isn’t fixed, so I am wondering what on earth is the problem?

First of all, you shouldn’t use wait anymore! There is now a replacement, task.wait(), which is part of the new task library which you should use instead.

Second of all, i think that for pets you can just use constraints instead (like AlignPosition and AlignOrientation, i believe it would be more performant!)

And last of all, can you provide some code? It is hard to diagnose a problem without information!

1 Like

make sure your loops break, it might be the pets tween service

What do your loops do?

Either offload the pets onto the client or use some BodyMover/Constrant for their positioning.

If your scripts are with

while true do

That is the cause of the game lagging I had this issue once before you should add lots of: wait() to your script or if you have alot of commands running at once like everyone clicking on a button or something make it so that it has different waits for each of the client

Well the problem is I need the loops to run the whole time the pet is active, so that can’t really help me, unless it does something else.

Ok for the wait thing, yeah I already fixed that part, because I took out all wait()s and just used wait(n > 1/30), is this still a problem?