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

Welding Script doesn't work exactly as intended?

I'm currently having a problem with my weld script, and the problem is that the script welds for only one part and doesn't weld any other, even though it's using a for loop. I think the root of the problem is that when it welds, it only welds the first child because the "i" is identified as a one, so the script welds the first child only. When I change the "i" into a different number, such as 3, it welds the third child. I don't exactly know how to fix this issue since I didn't originally create this script. Anyone know how to fix this problem?

function weld(x,y)
    weld = Instance.new("Weld")
	weld.Part0 = x
	weld.Part1 = y
	local CJ = CFrame.new(x.Position)
	local C0 = x.CFrame:inverse()*CJ
	local C1 = y.CFrame:inverse()*CJ
	weld.C0 = C0
	weld.C1 = C1
	weld.Parent = x
end
function Get(A)
if A.className == "Part" or A.className == "WedgePart" or A.className == "UnionOperation" then   
	weld(script.Parent.Part4, A)
	A.Anchored = false
else
	local child = script.Parent:GetChildren() --Mainly This Code
	for i = 1, #child do
	Get(child[i])
end
end
end

function Finale()
Get(script.Parent)
end
Finale()

1 comment

0

anyone?

1 answer

Your problem is that you haven't put a loop there!

Get rid of that Finale() function! That's part of the problem!

local middle = script.Parent:FindFirstChild("Root") -- Assumes there is a root part. You can name it to whatever.

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

function StartWelds(model)
   if model then
      for i,child in pairs (model:GetChildren()) do
          if child:IsA("BasePart") or child:IsA("UnionOperation") then
              weld(child, middle)
              print(':D')
          end
      end
   end
end

And there you have it! If you have problems, tell me and I'll fix it!

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