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("WeldConstraint")
weld.Name = "CubeWeld"
weld.Part0 = cubeFolder:FindFirstChild("CubePart1")
weld.Part1 = cubeFolder:FindFirstChild("CubePart2")
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.)

Could you please show the code you are using to tween the parts?

U need to tween the primary part of the model as I remember

It’s not a model. It’s just 2 seperate parts.

To tween a weld you need to tween the CFrame. Your previous post was the same exact issue.

I am just tweeing CubePart1, moving it and rotating it.

Yes so I asked how to fix it and no one helped me so I thought I will repost…

When I use CFrame in the tweenings I need to specify the lookAt vector, but I don’t know where it’s looking at I just know the degrees I want it to rotate.

Could you explain more of what you are trying to achieve?

I am trying to make it so that when CubePart1 moves the other cube will stick to it. I am moving CubePart1 by tweening, whenever the player presses a certain key.

image

(CubePart1 is the bottom cube, CubePart2 is on top of it.)

I’m not sure exactly why CFrame would not be an option? But it will be required if you want to tween objects with welds.

Because you create a CFrame for the tween goal.
I am tweening orientation and position, and I know how much degrees I want to rotate it by how would I know where it’s facing?

I’m not sure. All I know is how your game creates a weld. If you could please provide additional code to get an understanding of what movements you are making the part do it would help.

Here you go, this is the tweening code:

function tweens.TweenCube(direction)
	if not inMotion then
		inMotion = true
		if direction == "UP" then
			if isHorizontal then

			else
				local tweenInfo = TweenInfo.new(
					0.5,
					Enum.EasingStyle.Linear,
					Enum.EasingDirection.Out,
					0,
					false,
					0
				)
				local tweenProperties = {
					CFrame = CFrame.new(Vector3.new(mainPart.Position.X + 4, mainPart.Position.Y, mainPart.Position.Z)) * CFrame.Angles(math.rad(mainPart.Orientation.X), math.rad(mainPart.Orientation.Y), math.rad(mainPart.Orientation.Z) - math.rad(90)),
				}
				local cubeTween = TweenService:Create(mainPart, tweenInfo, tweenProperties)
				
				cubeTween:Play()
				cubeTween.Completed:Wait()
				
				mainPart.Orientation = Vector3.new(0, 0, 0)
			end
		elseif direction == "DOWN" then
			if isHorizontal then
				
			else
				local tweenInfo = TweenInfo.new(
					0.5,
					Enum.EasingStyle.Linear,
					Enum.EasingDirection.Out,
					0,
					false,
					0
				)
				local tweenProperties = {
					CFrame = CFrame.new(Vector3.new(mainPart.Position.X - 4, mainPart.Position.Y, mainPart.Position.Z)) * CFrame.Angles(math.rad(mainPart.Orientation.X), math.rad(mainPart.Orientation.Y), math.rad(mainPart.Orientation.Z) + math.rad(90)),
				}
				local cubeTween = TweenService:Create(mainPart, tweenInfo, tweenProperties)
				cubeTween:Play()
				cubeTween.Completed:Wait()
				mainPart.Orientation = Vector3.new(0, 0, 0)
			end
		elseif direction == "RIGHT" then
			if isHorizontal then
				
			else
				local tweenInfo = TweenInfo.new(
					0.5,
					Enum.EasingStyle.Linear,
					Enum.EasingDirection.Out,
					0,
					false,
					0
				)
				local tweenProperties = {
					CFrame = CFrame.new(Vector3.new(mainPart.Position.X, mainPart.Position.Y, mainPart.Position.Z + 4)) * CFrame.Angles(math.rad(mainPart.Orientation.X) + math.rad(90), math.rad(mainPart.Orientation.Y), math.rad(mainPart.Orientation.Z)),
				}
				local cubeTween = TweenService:Create(mainPart, tweenInfo, tweenProperties)
				cubeTween:Play()
				cubeTween.Completed:Wait()
				mainPart.Orientation = Vector3.new(0, 0, 0)
			end
		elseif direction == "LEFT" then
			if isHorizontal then
				
			else
				if isHorizontal then
					
				else
					local tweenInfo = TweenInfo.new(
						0.5,
						Enum.EasingStyle.Linear,
						Enum.EasingDirection.Out,
						0,
						false,
						0
					)
					local tweenProperties = {
						CFrame = CFrame.new(Vector3.new(mainPart.Position.X, mainPart.Position.Y, mainPart.Position.Z - 4)) * CFrame.Angles(math.rad(mainPart.Orientation.X) - math.rad(90), math.rad(mainPart.Orientation.Y), math.rad(mainPart.Orientation.Z)),
					}
					local cubeTween = TweenService:Create(mainPart, tweenInfo, tweenProperties)
					cubeTween:Play()
					cubeTween.Completed:Wait()
					mainPart.Orientation = Vector3.new(0, 0, 0)
				end
			end
		end
		inMotion = false
	end
end

I am basically rotating and moving the cube at the same time so it would look like it’s rolling.

Just follow this tutorial: Introduction to Tweening Models

I am not trying to tween them both, I am only trying to tween CubePart1 so that CubePart2 will stick to it.

I just changed it to CFrame but it still doesn’t work.
(Also edited the code I sent now)