CFrame manipulation: unintended twisting help!

So I have this code which generates cframes in bezier curves as shown below but the cframes aren’t twisted in the correct way.

This is what I’m getting.
image
image

An this is what I want.

As you can see, the look vector in the video always faces the “same direction” as opposed to the picture of what I’m getting which makes all the look vectors face upwards.

here’s what I have so far of the important part of the code:

	for i = 1, nodes do
		local prevBonePos = reparamBezier((i - 1) / nodes, startPos, middlePos, endPos, nodes)
		local nextBonePos = reparamBezier((i + 1) / nodes, startPos, middlePos, endPos, nodes)
		local bonePos = reparamBezier(i / nodes, startPos, middlePos, endPos, nodes)

		local boneDirection = nextBonePos - prevBonePos

		local newCFrame = CFrame.lookAlong(bonePos, boneDirection)
			* CFrame.Angles(math.rad(90), 0, 0)
			* CFrame.Angles(0, math.rad(-180), 0)

		CreatePart(newCFrame)
	end

And here’s a toy example you can use to generate the result yourself. (please note that reparamBezier is from this Reparameterization: Tips and Tricks)

BezierExample.rbxl (56.3 KB)

Any help would be greatly appreciated, thanks!