How do I make my game less laggy?

Currently, on one of my games, I am facing a lag crisis.
After about, for an estimate, 1 hour of playtime, the game starts lagging a lot.

I do not know what is causing the lag exactly,
but here are what I believe the big lag components to my game:

  • Constant remote firing from the player (not much data being sent)
  • Constant cloning of objects

Is spawning too many parts bad for a game?
And is there anyway to fix any of this?
Any help would be greatly appreciated.

3 Likes

One thing which a fellow friend of mine have had on there game is the part count. Could that be the issue with the lag as you say there is lots of cloning objects meaning there will be more parts inside the games? Could you destroy any parts which are cloned and no longer needed?

And to this part as I said yes having to many parts can cause lag mainly in the areas of the lots of parts but the more you are away from the parts the less lag.

What reason are you using frequent RemoteEvents for? Maybe you could shorten how many or how frequent the RemoteEvents are firing.

For the cloning, you could delete the clones after they are unnecessary?

That’s a main problem I have with the game, because the part problem is not one that can be fixed simply. Its a game where food spawns around the map, lots of it, and you have to find it. There is no way to destroy cloned parts already in use, though, parts do despawn.

You could delete them after a while. For example after a minute or so, the clone gets Destroyed.

They do get destroyed, but if a player picks them up or eats them, they don’t get destroyed. I couldn’t find a work around of that.

There’s most likely a memory leak somewhere in your game.

So you can’t do something like it getting destroyed after the player eats it? How is your system working?

Mind telling me what you mean by a memory leak? I am not totaly sure what you mean.

Try this.

Instead of cloning and deleting it re-uses the same parts.

Yea I am not sure why he can’t. Surely you could just like have a table or something to keep track of what is eaten.

Basically, once a part is spawned the world, the player must find it. It gives a certain amount of hunger and water, whatever. It has 10 uses, meaning the player must click on it 10 times to get the resources from it. Once they click on it once or pick it up it no longer despawns, because the player might house that food in their reserves.

1 Like

They are sections of memory that are never cleaned up.

More information:

1 Like

Thanks I will take a read of it.

1 Like

Does their reserves save with DataStore or something? If not, you could :Destory() them after a while (if you wanted to make some sort of effect if they keep it too long) or delete it all when they leave. You might just want to do both.

Also, I believe this best belongs in #help-and-feedback:scripting-support.

Yes like @chubbypig332211 said can’t you store it in like data terms instead of like an object. Even if you need an object you could save it as data and when it needs to be used clone/add in the part for the once use or something like that

Don’t show them unless they are in the players line of sight.

Here is a list:

  • Delete un-needed welds
  • Set all union’s render to automatic
  • Make sure your scripts are optimized
  • Make sure your inserted parts are going to be destroyed after a certain amount of time to reduce lag

Yeah, I’ve tried all of these methods. Still no good.