Cannot make a cframe with 0 rotation around y axis

This is probably so simple, but I literally cannot figure this out after an hour of trying and looking thinigs up.

SO, I’m following this tutorial to create a placement system: Creating A Furniture Placement System

Everything works fine, except I want it so that no matter how the canvas part is rotated around the up and down axis:

This is what I want to happen:
image

This is what is currently happening:
image

This is the function in question from the article that calculates the cframe:
(in my code I removed rotation and set it to zero so that players cannot rotate the placements)

function Placement:CalcCanvas()
	
	local canvasSize = self.canvasPart.Size

	-- convert to world space
	local cf = self.canvasPart.CFrame * CFrame.fromMatrix(-BACK_CFRAME*canvasSize/2, RIGHT_CFRAME, TOP_CFRAME, BACK_CFRAME)
	-- use object space vectors to find the width and height
	local size = Vector2.new((canvasSize * RIGHT_CFRAME).magnitude, (canvasSize * TOP_CFRAME).magnitude)

	return cf, size
end

function Placement:CalcPlacementCFrame(position)
	
	-- use other method to get info about the surface
	local cf, size = self:CalcCanvas()
	
	-- rotate the size so that we can properly constrain to the surface
	local modelSize = self.model.PrimaryPart.Size
	modelSize = Vector3.new(math.abs(modelSize.x), math.abs(modelSize.y), math.abs(modelSize.z))

	-- get the position relative to the surface's CFrame
	local lpos = cf:pointToObjectSpace(position)

	-- the max bounds the model can be from the surface's center
	local maxBounds = (size - Vector2.new(modelSize.x, modelSize.z))/2

	-- constrain the position using size2
	local xClamp = math.clamp(lpos.x, -maxBounds.x, maxBounds.x)
	local yClamp = math.clamp(lpos.y, -maxBounds.y, maxBounds.y)
	
	return cf * CFrame.new(xClamp, yClamp, -modelSize.y/2) * CFrame.Angles(-math.pi/2, 0, 0)
end

Rotating the model about the Y-Axis (what you’ve been avoiding) is what you’re looking for. Your CFrame is currently set to rotate the model by -pi/2 rad about the X-Axis; change that.

What do you mean I’ve been avoiding? And unfortunately, changing that value does not affect it’s rotation around the y-axis (up and down). I can change the y value and it does rotate it around the y axis, except this rotates the cframe relative to what it already is- but I just want to set it to zero.

Oh, in that case, you need to get the target position and return a CFrame with just the position in it:

cf *= CFrame.new(xClamp, yClamp, -modelSize.y/2);
return CFrame.new(cf.Position);