Weld Doesn't Work

I have 2 parts, Cube1 and Cube2. They are located inside a folder and I want to make a weld so that when one moves, the other will too.

The code that creates the weld is this:

local weld = Instance.new("Weld")
weld.Name = "CubeWeld"
weld.Part0 = cubeTable[1]
weld.C0 = cubeTable[1].CFrame:Inverse()
weld.Part1 = cubeTable[2]
weld.C1 = cubeTable[2].CFrame:Inverse()
weld.Parent = cubeFolder:FindFirstChild("CubePart1")

This doesn’t work, of course. So I am asking for help: Anyone knows how to fix this?
(I am moving one cube with a tween and I want the other cube to “stick” to the other one and move with it.)

2 Likes

Another note is that the script DOES run, I see that the weld is created and it is attached to the parts as expected.

1 Like

Maybe put the parts in a hierarchy with the cube that you are tweening as the parent? Not sure

1 Like

What is a hierarchy? (ahhhhhhhhhhh)

2 Likes

Basically when you put a part into another part. It’s really easy to do- just drag Cube 2 into Cube 1 and and weld the 2 parts together. (You can use a plugin to do so, instead of a script.)

Ask me if you have any other questions on part hierarcies.

1 Like

And what would the weld’s parent be?

That I’m not sure of: maybe Cube01??? You can try and experiment with both to see which one works.

1 Like

Alright I will experiment with that.

1 Like

Switch out Instance.new("Weld") with Instance.new("WeldConstraint").

1 Like

Why does that matter?
I’d like to know so I will understand for next time I do these things.

It’s the more modern form of a weld that in my testing actually works. In the past I have made this mistake and using a WeldConstraint fixes it.

1 Like

It doesn’t work.
Part0 is the CubePart1,
Part1 is the CubePart2,
and the weld is parented to CubePart1.

Did you remove C0 and C1 from your code when using the WeldConstraint?

1 Like

Yes I did, it gave me an error when I didn’t.

Are you tweening the CFrame or Position? I found a post on the DevForum that mentioned that Position causes issues with welds.

1 Like

I am tweening position and orientation separately.

I need to specify the degrees for my code, I can’t use look vectors. That’s why I am using position and orientation separately.
How do I fix this then?

1 Like