CFrame math help

How do I properly multiply a CFrame so a windows can move on a wall?

What I have

--Wall Position (-25.25, 8, 22.2) Size (21, 16, 0.4)
local LookVector = Wall.CFrame.LookVector --(0,0,-1)
local Pos = LookVector * Wall.Position --(0,0,22.2)
local ToCF = --How do I make the X,Y the wall position and keep the Z -22.2?)

Thanks and have a good day!

Why don’t you just change the position instead? If you don’t need the window to have the same orientation of the wall, or look at the wall, just use the Position property.

The thing I’m trying to move is a model, and it moves randomly around the wall (Which rotates)

Alright, if I understood right you also need to change the rotation. If it’s a model, and it has a PrimaryPart, you can use :SetPrimaryPartCFrame():
This should do it. Try it and tell me if it works.

The Wall.Position.X and Wall.Position.Y are randomly generated every second. And the Z mighth not be the right axis. The CFrame.LookVector decides based of rotation

local Model = script.Parent.SquareWindow

--Get the wall position
local LookVector = script.Parent.Part.CFrame.LookVector
LookVector =,math.abs(LookVector.Y),math.abs(LookVector.Z))
local WallPosition = script.Parent.Part.Position * LookVector

--Do some maths
local WindowPosition = Model:GetPrimaryPartCFrame().p
local WindowsPos = WindowPosition - (WindowPosition * LookVector)
local ToCF = + WindowsPos)


This is to help incase someone else has this same problem.