Setting a :Clone() parent, Destroying or Debris:AddItem() all creates an extremely noticeable lag spike

If you do any of the following it creates a noticeable lag spike:

  • Setting a clone’s parent to the workspace
  • Using :Destroy() on literally anything
  • Using Debris:AddItem() on literally anything

This is a serious issue, as I am making a game where bosses are constantly cloning and destroying projectiles you have to avoid. I’m trying to avoid having to cache clones as much as possible, so if you have any other solutions let me know.

3 Likes

why would you be avoiding to cache? if you are cloning and destroying large amount of instances in short timeframes it’s bound to lag

1 Like

Uh, cache would be a life saver here.
You’re just adding more work into the Garbage collector and the game itself, which can cause performance issues.

For one, GC is cleaning memory up from the destroyed instances / unused data.
And second, the game will be slower when you’re just constantly creating new Instances.

The cache helps you to avoid initializing the projectiles once again, and just re-using an old projectile when the game asks for another one, or making a new one if the cache ever runs out of them.

1 Like

For Destroy as a replacement you could use.Parent = nil, and the same for AddItem.

Just realized I replied to the wrong person my bad :skull:.

3 Likes

Try reusing projectiles from a pool instead of constantly creating and destroying them. optimizing your code and avoiding unnecessary computations can also help improve performance.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.