Destroying animate script is laggy


image

I tried destroying a character and noticed that it was extremely laggy. I tested it with a fresh baseplate that just simply destroys the animate script of a rig I placed down and I was able to replicate the lag. Below is a screen shot where the micro profiler shows the lag spike. Is lag when destroying a character with an animate script simply unavoidable or is there a better way to destroy characters?

Specs
16GB RAM
RTX 4060
RYZEN 7 8845HS
WINDOWS 11

4 Likes

seems to only happen in studio. I guess this means it’s either a server only lag spike or a studio only lag spike.

I’ve tried it in team test and both the server window and client window lags equally as much. I’m guessing that this is a studio issue

1 Like

Instead of destroying it, you could add a local script with the same name in StarterCharacterScripts, you could leave it empty which should not make any bugs appear.

doesnt work
thirtycharacters thirtycharas


it seems that it’s not the children of the animate script causing the issue as any local script being destroyed will cause lag

I meant to make a local script, then name it Animate, which would override the normal script.

and then you don’t need to destroy the script.

I want to destroy this local script not to disable animations but to cleanup a rig. I want to keep a player’s limbs after they die but not the rest of the model. I could just not delete the animate script but over time there would then be lots of animate scripts piling up which probably won’t be that bad for performance but it irks me

So you want to make some type of ragdoll when you die that would stay there when you respawn?

Then, you could make a template rig, copy that rig, then apply humanoid description on that dummy and then just put the rig in place of the player.

they don’t respawn so I don’t want to keep their original character around

you could delete the original character after when the appearance loaded and the clone is positioned.

I would need to delete the animate script inside the character

Here’s a few things I need clarification on first:

  1. Why are you destroying LocalScripts for any reason?
  2. Why are you destroying the animate script specifically?
  3. Have is your actual issue as to why you’re destroying any scripts at all?

I want to destroy a model because I can’t have models sitting around forever. Those models have animate scripts, so when I destroy those models, the animate scripts are destroyed. Destroying a script is laggy. So when I destroy a model I want to destroy, there will be a big lag spike.

Are you destroying it from the client or the server? Destroying an NPC model takes a good amount of computational resources because it first has to destroy every child of any child that has elements within it. It’s better to not destroy them for this reason alone, and you should either re-parent it to something else and destroy them from the server later.