Welded parts domino effect on deletion

In this script, it runs a detection loop to see whether different bricks have a weld, or if their weld is broken. The problem is that it creates a sort of domino effect, that gets sent through the whole build since the deleted blocks get destroyed, causing the weld to become inactive.

is there anyway of moving around this problem? I cant think of a way to assign a variable to the blown up parts, then checking if the weld is attached to those. Any help is appreciated

local runservice = game:GetService("RunService")
local ifweld = script.Parent

local function WeldFinder()
	for i,parts in pairs(ifweld:children()) do
		if not parts:FindFirstChild("NAAP_Weld") then
			if parts.Name == "NAAP_PrimaryPart" or parts.Name == "WeldHandler" then
				-- Leave blank
			else

				while parts.Transparency <= 1 do
					parts.Transparency += 0.05
					task.wait(1)
				end
				if parts.Transparency >= 1 then
					parts:Destroy()
					task.wait(0.1)
				end
			end
			
		else
			if parts.NAAP_Weld.Active == false then
				while parts.Transparency <= 1 do
					parts.Transparency += 0.05
					task.wait(1)
				end
				if parts.Transparency >= 1 then
					parts:Destroy()
					task.wait(0.1)
				end
			end
		end
	end
end

runservice.Heartbeat:Connect(function()
	WeldFinder()
end)
1 Like

Add a BoolValue to the parts and change it to true when they “blow up”.

Then check the BoolValue with your loop and see if it it true before deleting the weld.

1 Like

would this also work for the parts that havent been directly blown up, but have broken welds?
EX:

	if parts.NAAP_Weld.Active == false then
				while parts.Transparency <= 1 do
					parts.Transparency += 0.05
					task.wait(1)
				end
				if parts.Transparency >= 1 then
					parts:Destroy()
					task.wait(0.1)
				end
			end

I’m not sure how your game works. I was just thinking about your comment: “I cant think of a way to assign a variable to the blown up parts”.

I am curious about this line of code, though:

if parts.NAAP_Weld.Active == false then

I was not able to create a scenario where the Active changed for a Weld or a WeldConstraint.

What is NAAP_Weld? Is that an actual Weld or WeldConstraint?

Sorry for the confusion, it’s a weld constraint.

this is what an example of whats happening looks like right now:
https://gyazo.com/8e6ce4acc8b3613bc92f10d5183c8181

as you can see the house will slowly fall apart due to it’s welds becoming inactive since one of the bricks get destroyed.

That’s a feature I wasn’t aware of. I see how it works now.

So, what code tells a part it has been damaged?

Maybe that code could “add” a BoolValue.

Then of you find the BoolValue you know the part is damaged.

@mc7oof mightve found a sneaky work around.

instead of destroying the blocks, im thinking of making their cancollide = false when they get to transparency == 1 (hit)

then It’ll run a script that, when all the parts are invisible or cancollide, it deletes them all.

do you think this could work?

I think I would just use an event listener so it takes care of itself.

Something like:

for _, weld in pairs (MyBlocks:GetDescendants()) do
	if weld:IsA("Weld") then
		weld.Active.Changed:Connect(function()

			-- you know it has changed

		end)
	end
end
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.