How can I remove a model without causing lag?

Hey developers.

How can I delete models without causing lag?

At the moment, I am using model:Destroy() but as the models have a substantial amount of parts the whole server will lag.

I attempted looping through all the parts and deleting the parts individually but that also causes lag.

Does anyone have a solution to this?

I am also having issues with lag when I reparent the model to workspace. All solutions are appreciated.

3 Likes

I wouldn’t say there is a possible way of having the lag be entirely avoided, and calling GetChildren() on a model with a ton of parts will lag harder.
Your best bet is Model:Destroy().

1 Like

Well, you could try to loop through all the parts in the model and then use a small wait between each part that gets destroyed, so that it doesn’t instantly delete all the parts, that should reduce the lag significantly.

Assuming that the model has an overly-excessive amount of parts, meshparts, etc. etc. unfortunately this wouldn’t be as useful since it would then take a lot of time to delete the entire thing. OP clearly intends for the model to be instantly deleted.

That’s what I’m doing, and it’s giving the same amount of lag but a longer time frame.

1 Like

I’ve been using Model:Destroy() (as stated in the OP) and it’s been causing lag.

Hmm, yes, you are right! What if @Winky_y could make a loading screen while deleting the parts so that the players don’t notice the lag?

I know. There’s not exactly a way to combat this. As seen by the last statement I made on the last post:

Your best bet is Model:Destroy() .

That’s what most games do isn’t it?

Every time there’s a model deletion request a 2 second loading screen for the whole server? That seems very counterintuitive if you ask me. I am removing 2-3 models per minute, so that just is not a viable solution.

1 Like

This is more than likely mid-game, so it wouldn’t really make any proper sense as to why you’d want a loading screen mid-game unless you were loading something - loading screens aren’t for deleting anything

In other words, there is no better way to combat this.

1 Like

True, can you explain more in depth the concept of your game and where you’re deleting these parts?

Deleting a model is deleting a model, and the context of that deletion is not very relevant.

Well, I’m sorry but if we don’t have enough information we can not come up with a reasonable solution.

You can try re-parenting the model to something that isn’t the workspace, as an example, maybe ServerStorage(?) and let the server handle the deletion of the models.

1 Like

Would moving the model to a very far away distance help? It’s the only thing I can think of

I’ve attempted to reparent all the parts to game.ServerStorage, and I had the same issue with lag.

I’ll give it a shot. That’s helpful.

That’s a good idea, but as stated above, when @Winky_y tried re-parenting, it caused lag too.

That’s because even when re-parenting to the ServerStorage, the parts are basically still there. When setting the primary part’s CFrame to a substantial amount of distance, I think it’d be one of the best solutions because it doesn’t involve affecting every single part (assuming that they are welded or that SetPrimaryPartCFrame moves the entire thing).

2 Likes