I have a script, as everyone here does have, and it lags whenever it runs. Its purpose is to make a table containing all the blocks in a given model, and do several iterations to found out which blocks are disconnected and destroy them.
It works great, but when it first runs, the computer/studio stops for a second before resuming. I thought it might be because :getchildren or :getconnectedparts() was taking a while to call, so I put in a tick() function to count how long it takes for the script to run. The results: practically instantaneous. “It took 0.016401052474976s to run this script”.
That can’t be right because my whole computer freezes for a good second whenever this script is called (I know its this script, its the only one running). I did notice that this script does run several times after its first run. Whenever it destroys a block, it recalls itself to calculate if it detects any other changes to the other blocks. Which is perfect, but it does it for every block in the model. I put a debouncer in, and it trims a good amount of the calls, but doesnt out right prevent it.
So, I wanna know if theres a way to found out WHAT is taking so much of my computer’s resources. If its something i should worry about, or if its just a studio thing. And if theres any way to prevent an event from being called several times all at once. (I already tried basic debouncer)
Thank you all for any advice!