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

How could I fix this script so Unions can be welded?

Where it says, if A.className == "UnionOperation" then and so forth, is what I have tried to edit. I'm trying to get a union part to weld, but it won't. How can I fix this?

function Weld(x,y)
	local W = Instance.new("Weld")
	W.Part0 = x
	W.Part1 = y
	local CJ = CFrame.new(x.Position)
	local C0 = x.CFrame:inverse()*CJ
	local C1 = y.CFrame:inverse()*CJ
	W.C0 = C0
	W.C1 = C1
	W.Parent = x
end

function Get(A)
**	if A.className == "Part" then
		Weld(script.Parent.Handle, A)
		A.Anchored = false
	if A.className == "UnionOperation" then
		Weld(script.Parent.Handle, A)
		A.Anchored = false**
	else
		local C = A:GetChildren()
		for i=1, #C do
		Get(C[i])
		end
	end
end

function Finale()
	Get(script.Parent)
end

script.Parent.Equipped:connect(Finale)
script.Parent.Unequipped:connect(Finale)
Finale()~~~~~~~~~~~~~~~~~

1 answer

✓ Accepted answer

When joining multiple conditions together, you need to use elseif for the later ones.

...
	if A.className == "Part" then
		Weld(script.Parent.Handle, A)
		A.Anchored = false
	elseif A.className == "UnionOperation" then
		Weld(script.Parent.Handle, A)
		A.Anchored = false**
	else
		local C = A:GetChildren()
...

In this case, though, this is redundant. The operation done on it is the same. Let's just use or and a single if:

...
	if A.className == "Part" or A.className == "UnionOperation" then
		Weld(script.Parent.Handle, A)
		A.Anchored = false
	else
		local C = A:GetChildren()
...

Let's be more general. UnionOperations and Parts are both *BasePart*s.

We can test if something is a BasePart using the :IsA method:

...
	if A:IsA("BasePart") then
		Weld(script.Parent.Handle, A)
		A.Anchored = false
	else
		local C = A:GetChildren()
...

Much shorter, cleaner, and more intuitive.

1 comment

0

It worked! Thank you so much!!!!

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