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

Help With Welds?

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

✓ Accepted answer

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)

7 comments

0

Nope, when I use the gun it still only shows up as a handle

0

Is it because they're Unions? Do Welds not work on Unions?

0

No, it's because on line 7 you made it so all the unions move to the same position when they are welded

0

I managed to sorta get it working. Thanks for your help?

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?

0

These two functions are what I wrote to correct for rotation in CFrame encoding. Good luck http://hastebin.com/ewemukinaf.lua

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

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