WeldConstraint

Show Deprecated

WeldConstraints are used to attach two parts together. The constraint makes sure that the parts stay in the same relative position and orientation to one another, meaning that if one part moves, the other will move the same amount. Even if the two parts are not touching one another, they can be welded together with a weld constraint.

The most common way to create a weld constraint is through the Studio Create menu in the Model tab (select Weld). This tool will act differently based on how many parts are selected when the tool is activated:

  • If no parts are selected when the Weld tool is clicked, the next two parts that are clicked on will be welded together. If the same part is clicked twice, no weld will be created.
  • If one part is selected when the Weld tool is clicked, the next part that is clicked on will be welded to the selected part.
  • If several parts are selected when the Weld tool is clicked, any parts in that selection that are touching or overlapping will be welded together.

Repositioning Welded Parts

Roblox handles moving a welded part differently depending on whether the part was moved using its Position or with its CFrame.

If a welded part's Position is updated, the part will move but none of the connected parts will move with it. The weld will recalculate the offset from the other part based on the part's new position.


1-- Create two parts and position them at the same height
2local partA = Instance.new("Part")
3local partB = Instance.new("Part")
4partA.Position = Vector3.new(0, 10, 0)
5partB.Position = Vector3.new(0, 10, 10)
6partA.Parent = workspace
7partB.Parent = workspace
8
9-- Weld the two parts together
10local weld = Instance.new("WeldConstraint")
11weld.Parent = workspace
12weld.Part0 = partA
13weld.Part1 = partB
14
15-- Update the position of the first part; the first part will move but the second will stay where it started
16partA.Position = Vector3.new(0, 20, 0)
17

In contrast, if a part's CFrame is updated, that part will move and any part welded to that part will also move. These other parts will be moved to make sure they maintain the same offset as when the weld was created.


1-- Create two parts and position them at the same height
2local partA = Instance.new("Part")
3local partB = Instance.new("Part")
4partA.Position = Vector3.new(0, 10, 0)
5partB.Position = Vector3.new(0, 10, 10)
6partA.Parent = workspace
7partB.Parent = workspace
8
9-- Weld the two parts together
10local weld = Instance.new("WeldConstraint")
11weld.Parent = workspace
12weld.Part0 = partA
13weld.Part1 = partB
14
15-- Update the CFrame of the first part; the second part will also move to maintain the offset of the weld
16partA.CFrame = CFrame.new(0, 20, 0)
17

Summary

Properties

Indicates if the WeldConstraint is currently active in the world.

READ ONLY
NOT REPLICATED

Toggles the constraint on and off.

NOT REPLICATED

The first part connected by the constraint.

NOT REPLICATED

The second part connected by the constraint.

NOT REPLICATED

Events

Methods

Properties

Active

Read Only
Not Replicated

True if the WeldConstraint is currently active in the world.

If the WeldConstraint or one of its parts is not in Workspace the weld will be inactive.

Rigid joints like Weld, Snap, WeldConstraint, Motor, or Motor6D may also be disabled due to conflicts with other rigid joints, such as joints between the same two parts or indirect cycles in the weld graph. Joints disabled this way may be re-enabled later when another joint or part is added or removed.

Duplicate WeldConstraints do not conflict because WeldConstraints derive their internal CFrames from the relative positions of their parts when they are enabled and all update when BasePart.Position or BasePart.Orientation is set on a part. The spanning tree may still disable them if they are redundant or form a cycle.

Enabled

Not Replicated

The Enabled property of a WeldConstraint sets whether the constraint is active or not. When this property is set to true, if the constraint's WeldConstraint.Part0 and WeldConstraint.Part1 properties are set, then the constraint will ensure that its two connected parts will be locked together.

Not Replicated

The Part0 and WeldConstraint.Part1 properties of a WeldConstraint set which two BasePart the weld connects. As soon as both properties are set and the weld is WeldConstraint.Enabled, the weld will lock the two parts together.

If Part0 or Part1 are ever set to new parts, then the WeldConstraint will instantly link the new part. The old part will no longer be constrained.


1local partA = Instance.new("Part")
2local partB = Instance.new("Part")
3
4partA.Position = Vector3.new(0, 10, 0)
5partA.Parent = game.Workspace
6
7partB.Position = Vector3.new(0, 10, 10)
8partB.Parent = game.Workspace
9
10local weld = Instance.new("WeldConstraint")
11weld.Parent = partA
12weld.Part0 = partAweld.Part1 = partB
13
Not Replicated

The WeldConstraint.Part0 and Part1 properties of a WeldConstraint set which two BasePart the weld connects. As soon as both properties are set and the weld is WeldConstraint.Enabled, the weld will lock the two parts together.

If Part0 or Part1 are ever set to new parts, then the WeldConstraint will instantly link the new part. The old part will no longer be constrained.


1local partA = Instance.new("Part")
2local partB = Instance.new("Part")
3
4partA.Position = Vector3.new(0, 10, 0)
5partA.Parent = game.Workspace
6
7partB.Position = Vector3.new(0, 10, 10)
8partB.Parent = game.Workspace
9
10local weld = Instance.new("WeldConstraint")
11weld.Parent = partA
12weld.Part0 = partA
13weld.Part1 = partB
14

Events

Methods