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

Is it possible to weld multiple parts to my player's hand without finding the exact positions?

I'm trying to weld a gun to my player's hands. It has multiple parts, but I don't know how I can do it all at once using a function. Can anyone help me with this? What I mean is like instead of having to create a weld for every part , for example w = Instance.new("Weld"), and doing that multiple (tens) of times, is there a way I can weld the weapon using a single function, and is it possible to animate it using animation editor if I do that?

1 answer

✓ Accepted answer

You can easily do this by iterating through all the parts under the weapon, and welding each of them.

local tool = script.Parent

-- make sure the parts are anchored before you run this function on them
function weldChildren(parent, p1)
	-- parent is the parent of the children that you want to weld
	-- p1 is the part each of the parts is going to be welded tonumber
	for _, v in pairs(parent:GetChildren()) do
		if v:IsA("BasePart") then -- make sure its a basepart so it doesn't error
			local weld = Instance.new("Weld")
			v.TopSurface = 0
			v.BottomSurface = 0 -- make sure they are smooth surfaces to avoid bugs
			weld.Parent = v
			weld.Part0 = v
		   	weld.Part1 = p1
		 	--CFrame of part1 relative to part0
		  	weld.C0 = v.CFrame:inverse() * p1.CFrame
			v.Anchored = false -- make sure that the parts are not anchored
		end
	end
end

weldChildren(tool, tool.Handle) -- calling function assuming tool is the tool, and tool.Handle is the part you want all parts to be welded to

And yes, you can animate it using animation editor

Hope it helped, if you have any further questions don't hesitate to ask.

8 comments

0

Thanks, this kind of helped, this shows how I can weld something to a tool, but how would I weld it to the hand?

0

I also have another question, how can I animate the model itself, doing this, I can animate the hands and body parts, but is it possible for me to animate the model?

0

No , animate hands model will move with hands.

0

Having a part named "Handle" under tool automatically welds the tool to the hands, animating the model of the tool itself cannot be done by animation editor, the only way it can be done by animation editor is by moving the hand, and the gun will be welded to the hands, otherwise it has to be done through a local script using CFrame

0

one last thing, how do u animate the model by itself, if u don't mind, you can also link me another article, post if you're busy thanks!

0

If you are using the animation editor to animate the model (easiest way), you will just put the gun onto the rig in animation editor, and you will animate the arm that is holding the gun (which will move the gun accordingly), and then you will use the other arm to do the rest of the animation (grab clip and reload for example), the other option is CFraming (this is a bit more advanced)

0

Here is the link that could help you understand how CFraming works, you will need to apply your knowledge from this page to be able to animate using CFraming: http://wiki.roblox.com/index.php?title=CFrame

0

Thanks, but how do I actually do it? If you could tell me that it would be really helpful! Thanks

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