Help with rotating weld angle

local part1 = script.Parent.Head -- the part that will be rotated holding the weld
local part2 = game.Workspace:WaitForChild("FacePart") -- the destination part
local weld = part1:FindFirstChild("Base") -- the weld we will rotate
local direction = (part2.Position - part1.Position).unit
local angle = math.atan2(direction.x, direction.z)
weld.C0 = CFrame.fromEulerAnglesXYZ(0, angle, 0) * weld.C0

So I’m trying to rotate a part’s weld so that the part can face another part on the map.
I can’t seem to get it to face the direction of “Part2”

This is currently what happens:
https://gyazo.com/3a91bb2394bcd2abb8bc9f42daf3da39

Any idea?

You could use a weld constraint to make things easier on yourself.
Edit: nvm, you’re trying to do multiple joints probably.

With a weld constraint you can just do:

part1.CFrame = CFrame.lookAt(part1.Position, part2.Position)

But that will rotate the part and everything attached to it. I need to rotate the weld, since that will only rotate the 2 parts that it’s attached to.

Figured it out.

	local base = script.Parent.Base
	local weld0 = base.Head
	local xy = Vector3.new(1, 0, 1)
	local y = Vector3.yAxis
	local targetCF = CFrame.new()
	local find = workspace:WaitForChild("FacePart")
	local look0 = CFrame.lookAt(base.Position, (find.Position * xy) + (base.Position * y))
	targetCF = base.CFrame:ToObjectSpace(look0):Inverse()
        weld0.C1 = targetCF
1 Like