Also, I found what the issue was. It was doing script.Parent:Destroy(), but it was only a part with a clickdetector, the script and mesh inside.
Can you show me how to find this out pretending I didn’t know what caused it?
Can you show me how to find this out pretending I didn’t know what caused it?
Scroll down until you find info on debug.profilebegin and debug.profileend, its how to add custom labels into microprofiler to debug what parts of your code are taking so long
Why is script.Parent:Destroy() taking so long though?
Im not entirely sure because you haven’t given much info on what you are actually destroying, but from experience the more instances in the structure you’re destroying the longer it takes. Whatever structure you’re working with probably has a LOT of instances to be taking that long.
If you aren’t able to do anything about this, I suggest trying to destroy the model in chunks at a time. So in practice, instead of destroying the entire model at once, get all its descendants with :GetDescendants, then loop through all of them and :Destroy them. You’ll want to add a “stepper”, meaning, for example, every 10 instances destroyed itll task.wait.