So this is a piece of code I have, It makes a model look in the direction fo something, but what if I only wanted to change the Y value and not the X and Z? I'm using .lookAt and it fills in all the values (XYZ), but I only want to use the Y and keep the X and Z the same.
script.Parent.PrimaryPart = script.Parent:FindFirstChildWhichIsA("Part") script.Parent:SetPrimaryPartCFrame(CFrame.lookAt(script.Parent.PrimaryPart.CFrame.Position, closest.Position))
You should use CFrame.fromMatrix, where you have control over the rightvector, upvector, and lookvector. I assume you wanted to change just the Y rotation, so heres the code for it
local pos = script.Parent.PrimaryPart.CFrame.Position local up = Vector3.new(0, 1, 0) local forward = closest.Position - pos local r = forward:Cross(up) -- constructing the rightvector script.Parent:SetPrimaryPartCFrame(CFrame.fromMatrix(pos, r.Unit, up)) -- CFrame.fromMatrix will automatically calculate the lookvector from the rightvector and upvector