Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Help with Welding?

Asked by 9 years ago

I am trying to weld a multi-part sword together, but every Weld script I have found does not work with my sword, but it does with other tools (the one they came with).

Any help?

Weld Script 1

local previous
local part = script.Parent:GetChildren()

for i = 1, #part do
    if part[i].ClassName == "UnionOperation" or part[i].ClassName == "Part" then
        if not previous == nil then
            local weld = Instance.new("Weld")
            weld.Part0 = previous
            weld.Part1 = part[i]
            weld.C0 = previous.CFrame:inverse()
            weld.C1 = part[i].CFrame:inverse()
            weld.Parent = previous
            part[i].Anchored = false
        end
        previous = part[i]
    end
end

wait(3)

Weld Script 2

function Weld(a, b)
    local w = Instance.new("Weld")
    w.Part0 = a
    w.Part1 = b
    local CJ = CFrame.new(a.Position)
    local C0 = a.CFrame:inverse() * CJ
    local C1 = b.CFrame:inverse() * CJ
    w.C0 = C0
    w.C1 = C1
    w.Parent = a
end

function Get(A)
    if A.className == "Part" 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()

I know they are quite large, but I have not found any errors in them. Any help is appreciated.

TheArmoredReaper

EDIT : I am trying to link this to a for loop, allowing the script to weld as many parts as needed. Every part inside my model is a Union, thus its class name is UnionOperation.

3 answers

Log in to vote
0
Answered by 9 years ago

I just tried it myself and it kept the bricks relative position AND rotation as all the bricks had different rotations. First, anchor the bricks and put them where you want them and the rotation you want. Then shove this script in it.

local function weldBetween(a, b)
    --Make a new Weld and Parent it to a.
    local weld = Instance.new("ManualWeld", a)
    weld.Part0 = a
    weld.Part1 = b
    --Get the CFrame of b relative to a.
    weld.C0 = a.CFrame:inverse() * b.CFrame
    --Return the reference to the weld so that you can change it later.
    return weld
end

for i,v in pairs(script.Parent:GetChildren()) do
    if not(v.Name=="Handle") and not(v:IsA(script)) then
        weldBetween(script.Parent.Handle, v)
        v.Anchored=false
    end
end
script.Parent.Handle.Anchored=false
0
OK, I know this works, but I cannot figure out how to link it to a for loop and apply it to a series of parts... TheArmoredReaper 173 — 9y
0
Also, that code works to keep the POSITION, but not the ROTATION, which I do not know (yet) how to maintain. TheArmoredReaper 173 — 9y
0
No, it keeps the rotation as well. when you use CFrame.new(x,y,z), CFrame does not reefer to the position but also the rotation. You could also CFrame.new(x, y, z, R00, R01, R02, R10, R11, R12, R20, R21, R22) to make the position and exact rotation the way you want it. CFrame is not only position but holds rotation. In this function put print(a.CFrame) and you'll see a whole list of numbers. Not j BobserLuck 367 — 9y
0
It does work, but I only had to modify the v:IsA(script) part because IsA only accepts strings! Thank you anyway ;) TheArmoredReaper 173 — 9y
Ad
Log in to vote
0
Answered by 9 years ago

If you are trying to find a script then why not use plugins.It works great and effecting.Search up welding/welder or auto-weld. Thats just tips other than that I can't figure this script out. BTW when getting all children you have to name every part the same thing as the part you want to get.

Log in to vote
0
Answered by 9 years ago

Alright if you wish to weld two parts together by their relative position then i recommend this

Inside a Script:


local weld = function(a, b) local w = Instance.new("ManualWeld") w.Part0 = a w.Part1 = b w.C0 = CFrame.new() w.C1 = a.CFrame:toObjectSpace(b.CFrame) return w end local Tool = script.Parent -- get tool local Handle = Tool.Handle for i, part in pairs(Tool:GetChildren()) do if part:IsA("BasePart") then if part.Name ~= "Handle" then weld(Handle, part) end end end
0
Thank you! Will test this right now... TheArmoredReaper 173 — 9y
0
Well, it does not work. No Welds are created... TheArmoredReaper 173 — 9y
0
Then Do w.C0 = a.CFrame:toObjectSpace(b.CFrame) DragonSkyye 517 — 9y

Answer this question