How do I detect if a weld has been broken?

From what I can reason, there should only be a few ways a weld can be broken.
Part0 is destroyed
Part1 is destroyed
or the Weld is destroyed

I didn’t see any built in events to detect this, so…
How would I go about this in the best possible way?

I was thinking I would need to check for a GetPropertyChanged for the Parent property of Part0 and Part1

Is this the correct way to detect a broken weld?

Thanks

1 Like

I’m pretty sure that’s one of the correct ways.

Edit: You can do property change for the weld itself too.

Which property would change on the weld? If either part0 or part1 were destroyed, would that change the part0 or part1 reference in the weld?

Part0 and Part1 don’t seem to change when the parts are destroyed

Ok… so if I did as in my original post, and I looked at the parent of the objects referenced in part0 and part1, such as…

RideWeld.Part0:GetPropertyChangedSignal(“Parent”):Connect(HandleWeldBreak)
RideWeld.Part1:GetPropertyChangedSignal(“Parent”):Connect(HandleWeldBreak)

would I need to keep track of these and somehow do a :Disconnect inside of HandleWeldBreak?

1 Like

I can’t get it to detect the destruction of part0 or part1 no matter what I try

local weld = workspace.Weld

local connection
connection = weld.Part0:GetPropertyChangedSignal("Parent"):Connect(function()
    if not weld.Part0.Parent then
    	weld:Destroy()
	    connection:Disconnect()
    end
end)

local connection2
connection2 = weld.Part1:GetPropertyChangedSignal("Parent"):Connect(function()
    if not weld.Part1.Parent then
    	weld:Destroy()
    	connection2:Disconnect()
    end
end)

This works for me

Welds have an Active property, which (from my testing) is only true when the weld is actually, well, active. This doesn’t fire any signals whenever it’s changed though (neither .Changed or :GetPropertyChangedSignal("Active") gets fired), so you’ll have to poll it in a loop.

It sucks, but it’s authoritative. Less complicated that checking if the parents of the three have changed, for sure.

3 Likes

For something as fundamental as knowing when a weld is broken by whatever reason, you would think there would be a simple event or something.

You could check if any object gets removed from the weld’s parent and check if the removed child was the weld.

1 Like