How do I make my part only rotate on an X axis towards a player

I am trying to rotate a part on only a single axis towards a player

I tried the following script but it hasn’t worked.

wait(.5)
Idle = game.Workspace.apiiela.HumanoidRootPart
while true do
	wait()
script.Parent.Parent:SetPrimaryPartCFrame(CFrame.new(script.Parent.Position.X,Idle.Position.X))
	end

The script rotates on all axis’s when I don’t have the X’s after .Position. But when I add them it stops it completely.

Any guidance would be helpful if you have spare time.
Thank you!

In this case, to restrict the movement in one axis you must compose a new target vector (in this case Idle) by changing just the axis you want to restrict.

wait(.5)
Idle = game.Workspace.apiiela.HumanoidRootPart
while true do
	wait()
	local modPosition = Vector3.new(script.Parent.Position.X, Idle.Position.Y, Idle.Position.Z)
	script.Parent.Parent:SetPrimaryPartCFrame(CFrame.new(script.Parent.Position, modPosition))
end

This way you restrict the motion on the Y-axis

local modPosition = Vector3.new(Idle.Position.X, script.Parent.Position.Y, Idle.Position.Z)
2 Likes