Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

[SOLVED]Why does this part detach when it is hit with an explosion?

function weld()
	local parts,last = {}
	local function scan(parent)
		for _,v in pairs(parent:GetChildren()) do
			if (v:IsA("BasePart")) then
				if (last) then
					local w = Instance.new("Weld")
					w.Name = ("%s_Weld"):format(v.Name)
					w.Part0,w.Part1 = last,v
					w.C0 = last.CFrame:inverse()
					w.C1 = v.CFrame:inverse()
					w.Parent = last
				end
				last = v
				table.insert(parts,v)
			end
			scan(v)
		end
	end
	scan(script.Parent)
	for _,v in pairs(parts) do
		v.Anchored = false
	end
end

weld()
script:Remove()

(It's supposed to be a welding script.)

1 answer

  1. It depends on the explosion's strength
  2. It only welds this once. when the weld is removed, you cannot get it back, so i designed this piece of code
while true do
wait(0.0000001) -- if longer, once hit with explosion, weld will not be in same position
	if not workspace.Map.Crate.Core:FindFirstChild("Part_Weld") then
		function weld()
			local parts,last = {}
			local function scan(parent)
				for _,v in pairs(parent:GetChildren()) do
					if (v:IsA("BasePart")) then
						if (last) then
							local w = Instance.new("Weld")
							w.Name = ("%s_Weld"):format(v.Name)
							w.Part0,w.Part1 = last,v
							w.C0 = last.CFrame:inverse()
							w.C1 = v.CFrame:inverse()
							w.Parent = last
						end
						last = v
						table.insert(parts,v)
					end
					scan(v)
				end
			end
			scan(script.Parent)
			for _,v in pairs(parts) do
				v.Anchored = false
			end
		end
		weld()
		print("welded!")
	end
end

--script:Remove()

This discussion is preserved as it was. New answers, comments, and votes are closed.