How to detect if a part has been loaded?

As you can see in the video above, I have made a gun that shoots holes into bricks with unions. If you look closely, you can see the parts “flicker”. I’ll demonstrate why I think this happens with horrible pseudocode.

When gun fired
Find part gun is fired at
Find parts within a 1x1x1 radius of where the gun was fired
Take those parts and union them (call this union U)
(U has no parent)
Negate a 1x1x1 cube at where the gun was fired with U (we will call this new union U2)
(U2 has no parent)
Set U2’s parent to workspace (making it visible)
Delete the part that the gun was fired at
end

All of this happens instantly with no waits. The problem is, (I think) when U2’s parent is set to workspace and the original part gets deleted, there is a time in between where the server is still doing the union calculations to make U2, and the part hasn’t loaded in yet. Since U2 isn’t loaded in yet, and the original part has been deleted, nothing shows up for a split-second until U2 loads in.

I was wondering if there’s a way to change my code to

wait until U2 is loaded in
Set U2’s parent to workspace (making it visible)
Delete the part that the gun was fired at

Thanks! :hugs:

You can use ContentProvider:PreloadAsync to detect when parts, or basically anything has loaded. It will yield the thread until the part loads, however.