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

Help With Welds?

Asked by
Scootakip 299 Moderation Voter
8 years ago
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


local weld = weldBetween(script.Parent.Handle, script.Parent.Part1, script.Parent.Part2, script.Parent.Part3, script.Parent.Part4, script.Parent.Part5, script.Parent.Part6)

I'm making a tool with multiple parts, and this is my weld script, but it still does nothing. Only the Handle shows up. Help?

1 answer

Log in to vote
0
Answered by
Validark 1580 Snack Break Moderation Voter
8 years ago

The problem is that you are passing too many arguments to the function weld. Instead, let's create a helper function that welds all the arguments together!

Here is my solution, with your code included:

local function weld(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 = b.CFrame:inverse() * a.CFrame
    --Return the reference to the weld so that you can change it later.
    return weld
end

local function weldBetween(...)
    local parts = {...} -- A list of all the arguments passed to this function
    local rootPart = parts[1] -- The first argument passed is going to be the part we weld everything to
    for a = 2, #parts do
        -- Weld all other parts to the first part
        weld(rootPart, parts[a])
    end
end

local welds = weldBetween(script.Parent.Handle, script.Parent.Part1, script.Parent.Part2, script.Parent.Part3, script.Parent.Part4, script.Parent.Part5, script.Parent.Part6)
0
Nope, when I use the gun it still only shows up as a handle Scootakip 299 — 8y
0
Is it because they're Unions? Do Welds not work on Unions? Scootakip 299 — 8y
0
No, it's because on line 7 you made it so all the unions move to the same position when they are welded Validark 1580 — 8y
0
I managed to sorta get it working. Thanks for your help? Scootakip 299 — 8y
View all comments (3 more)
0
One more question: When I build the gun, there are parts of it that aren't always facing forward, and that effects the way its welded. Is there any way to fix it without having to change the way the gun is built? Scootakip 299 — 8y
0
These two functions are what I wrote to correct for rotation in CFrame encoding. Good luck http://hastebin.com/ewemukinaf.lua Validark 1580 — 8y
0
That script doesn't do anything for whatever reason. I was messing around and got it working at some point. Without that script. I have no idea how or why, but it worked. I accidently closed out of that window........ I'm so close to giving up Scootakip 299 — 8y
Ad

Answer this question