How to simple weld two parts keeping their cframes

Hello, how do I weld two parts, this is what I know, and no I can’t use the weld constraint,

weld = Istance.new(“Weld”)
weld.Parent = part1
weld.Part0 = part1
weld.Part1 = part2
weld.C0 = ???
weld.C1 = ???
The ‘???’ means that I don’t know what to put there.

8 Likes

Why can you not use a WeldConstraint? It does exactly what you want.

Weld Constraint will ignore Orientation, that I want to avoid, I perfectly know it’s a way better than the weld. My objective is to make a valve that rotating, will let the spaceship rotate too, I failed with CFrame so I’m using welds.

I already made the valve rotate, so I just need a way to rotate the spacship, with an orientation that I have.

Orientation shouldn’t be ignored by WeldConstraints. If you need the C properties though, that’d be more understandable, since WeldConstraints do not offer that.

Create a new CFrame using only the position of Part0, then set the C0 and C1 to the inverse of the CFrame of Part0 and Part1 respectively, multiplied by the previously created CFrame. This kind of stuff you can find in toolbox resources involving model-welding operations.

local weld = Instance.new("Weld")
weld.Part0 = part0
weld.Part1 = part1
local offset = CFrame.new(part0.Position)
weld.C0 = part0.CFrame:Inverse() * offset
weld.C1 = part1.CFrame:Inverse() * offset
weld.Parent = part1

That should do the trick.

6 Likes

I mean, I can use WCs but I need a way to add an orientation to a cframe.

This is what you need.

local weld = Instance.new("Weld", handle)
weld.Part0 = part0
weld.Part1 = part1
weld.C0 = part0.CFrame:toObjectSpace(part1.CFrame) * CFrame.Angles(math.rad(90),0,0)
weld.C1 = CFrame.new()
1 Like

Ok lemme do a better question, let’s say I have a cframe and an orientation, how do I apply the orientation to a CFrame, doing that I can use WCs that ware better.

1 Like

What are you asking?? What do you mean by a CFrame and an orientation??

What are you trying to acheive?

1 Like

So, I have an orientation, but using WCs I can’t just put it there, I need to include the orientation in the CFrame.

If you’re asking to weld the parts, and have that part relatively in the same distance from the other part’s location, the only thing I could think of would be this:

Weld.C0 = part1.CFrame:Inverse() * part2.CFrame

Aside from that, I don’t think I understand your question.

But what is your actual use case - if you tell us what you’re trying to achieve (lets say you want to weld a gun up), that’ll help us

So, I need to rotate a spaceship, having the orientation it has to get, the space ship is welded with weld constraint so I can’t set just orientation on the base of the spaceship, but I need to set his cframe, but how do I set a cframe having an orientation?

this is all i do and it works beautifully

local weld = Instance.new("Weld")
weld.Part0 = part0
weld.Part1 = part1
weld.C0 = part0.CFrame:Inverse()
weld.C1 = part1.CFrame:Inverse()
weld.Parent = part1
20 Likes

now how would I make this gun look at where its meant to aim?

			GunWeld.C1 *= cfla(gunpos, gunpos + gundir).Rotation -- or c0