How do I stop :Remove() from causing a lag spike?

so basically, i am using :Remove() to destroy an object after it gets picked up. but, in doing so, it causes a lag spike.

i cannot use destroy or clearallchildren because it causes and error in my custom prompt script (the script includes checking all children of the promps parent, and it gives an error that children are nil or whatever lmao)

i also tried setting the prompts parent to nil which still lagged. (+ objects still visible in game using this method, which i dont want)

is there any way to get around this? probably not, but if you need any more additional information let me know.

Instance:Remove() is a deprecated method meaning that it is no longer updated or maintained by Roblox and should not be used in new work.

It would be beneficial to determine the cause of the error when you attempt to use :Destroy() and fix it. If you haven’t tried already, consider using the Debris Service.

1 Like

remove is literally the most unperformant way to destroy something

if your scripts is erroring on destroy there’s probably a problem

1 Like

:Remove does not “destroy” the object. It’s just a (probably slower) version of object.Parent = nil.

1 Like

thank you! lol i didnt realize remove was so bad.
i fixed the error with my other script when destroy is used.
although it still lags when the object is destroyed :sob:

What does the object look like to be causing a lag spike when destroyed?