DestroyHeight is an alternate way of handling fallen parts with lots of customization.
The only two main differences are:
It now uses the :Destroy() method to remove parts, and not just sets their parent to nil (This is a bit useful for garbage collection)
There is a bit of delay between each height check (You can lower it in settings, but then DestroyHeight will cause more lag)
How to use:
Make sure you’ve disabled FallenPartsDestroyHeight by running this in the console: workspace.FallenPartsDestroyHeight = 0/0
Require the module and call the initialize function in a server script
What you can customize:
Height at which the parts destroy at
The destroy logic (What happens to a part when it’s below the destroy height)
Delay between each height check (Lower delay increases lag)
A table of tags to exclude. A part with at least one of the tags from the table won’t be destroyed if it’s below the destroy height (This is initially why I even wanted to make this module!)
Whether to destroy non-humanoid ancestors of monitored parts that are direct CHILDREN of Workspace (Do you sort your Workspace by models? Then turn this on)
Whether to also destroy anchored parts or not (Can take a huge toll on performance, not like anyone is gonna use this though)
All options above are able to be changed in other scripts! (…I’m not sure if that’s unique enough to list here)
All of these options are set to behave as close as possible to FallenPartsDestroyHeight by default
Important note:
If a part becomes unanchored while initially being anchored, you will have to call DestroyHeight.MonitorPart() on said part, otherwise it’ll fall forever!
I’m surprised something like this hasn’t been made before. I honestly had a lot of fun coding this as well
I figured that it’d be more efficient to make my own parts table and update its contents by using workspace.DescendantAdded and DescendantRemoving, and not just loop through the entire workspace each heartbeat.
If your question is more about… my code just being bad, then take a look at this answer to a thread asking about GetPropertyChangedSignal(“Position”) not working. Unfortunately, it seems like there’s no better way to do this.
Fixed a lot of bugs, memory leaks, etc. (I’m kind of ashamed that I released DestroyHeight at such a raw state honestly)
Removed option to fully destroy humanoid models as you wouldn’t be able to respawn if it’s turned on
Added a delay option that delays the height check loop
(Suggested by @UniDevx)
Added an option to not destroy non-humanoid ancestors of monitored parts that are direct children of Workspace (For anyone who sorts their Workspace by models like me)