How can I weld a part between two parts?

Basically, I want to weld a part between two parts, right into the middle. That two parts are character hands and the part I want to weld is a rock. All parts have ever-changing size, rotation and hands have ever-changing distance between. I have no problem with loops while weld is active.

What I’ve tried so far is this:

local w = Instance.new("Weld")
w.Name = "RockWeld"
w.Part0 = RightHand --Right hand of our character
w.Part1 = NewRock --Rock I want to weld
spawn(function()
	while w.Parent do
		--Mathematical solution I've tried
		local MidPoint = (RightHand.Position + LeftHand.Position)/2
		MidPoint = MidPoint + Vector3.new(0, -Str*RockHeightModifier, 0)
		local C0 = MidPoint - RightHand.Position
		w.C0 = CFrame.new(C0)
		wait()
	end
end)
w.Parent = RightHand
NewRock.Parent = Char
1 Like

So then I can help more directly, is this a tool or a normal part, I can help with both.

1 Like

Get this plugin, should do the trick: Weld - Roblox

2 Likes

It’s normal, I prefer to not use tools

1 Like

Does this plugin supports in-game coding or ever-changing positions in-game? I don’t think it would handle my problem :confused:

1 Like

So you want to weld a part to a part and change the weld through a script like a CFrame animation?

1 Like

I want to create the part, weld it, keep weld C0 changing as long as animation keeps on and then break it. All in-game.

There are two ways, one: use a weld constraint and choose the parts, or two: use a union so then they are always together but you cant edit individual parts.

Thanks for your answer, but I am not truly sure you understand my question. Still I appreciate it!

So you are running an animation while changing the C0 of the motor6d that is in the animation?

1 Like

No, it’s a weld I’m trying to change. It’s not included in animation but welded to a part that is playing with animation.
Here, this should describe.

As you can see in this gif, I can’t get rock between my hands. That’s the exact problem. I feel like I need a mathematical solution that’s all, but please feel free to suggest anything that would solve this.

Is the rock being thrown using physics or is it being welded through the air?

1 Like

Using physics. I delete weld just before throwing process starts.

Did you try welding it to HumanoidRootPart since that is centered?

1 Like

Thought of it. How can I find the exact C0 for welding to HumanoidRootPart though? Pythagorean Theorem?

Try multiplying the C0 with CFrame.New(x,y,z) maybe?

1 Like

That doesn’t seem so easy, or I am missing something here. Absolutely easier than hand welding though…


I assume I need red vector. How can I get it? It can easily change according to HumanoidRootPart’s CFrame

I will do some work and deliver the code for you if I can. Probably by tomorrow- i’ve done something similar to this.

1 Like

Thank you very much it would be really lovely! I’ll try something either.

mygif

Okay so I think i’ve done basically in principle what you want. It was pretty simple and the code is easy and clean. As you can see, I also modified it so the ball goes up a little bit so when you animate it it can look even more realistic and like part of in-game physics. This is the code- let me know if you need anything else. Just add this in a script in a sphere like similarly in the gif.

wait(4)

local charName = “crossbar”

local sphere = script.Parent
local char = workspace:WaitForChild(charName, true)

local W = Instance.new(“Weld”)
W.Part0 = sphere
W.Part1 = char.HumanoidRootPart

W.C0 = CFrame.new(0, 0, 1)

W.Parent = char.HumanoidRootPart

wait(5)

for i = 0.1, 1, 0.1 do

W.C0 = CFrame.new(0, -i, 1)
wait(1)

end

print(“Welding done!”)