How do I rotate some thing on x axis using CFrame?

I have these two pieces of code in a local script and they won’t work together. I am trying to make the player’s Upper Torso face the camera, and the other piece to make the Upper torso move left and right , but it won’t work. It only makes the player’s uppertorso face the camera. How can I fix this? If you don’t understand, let me know

runService.RenderStepped:Connect(function()
      if canaim.Value == true then
			if aim == true then
				local rootPart = Character:FindFirstChild("HumanoidRootPart")
				local torso = Character:FindFirstChild("UpperTorso")
				local rx, ry, rz = Camera.CFrame:ToOrientation()
				torso.LeftShoulder.C1 = CFrame.new(torso.LeftShoulder.C1.Position)* CFrame.Angles(-rx/1.85,0,0)
				torso.RightShoulder.C1 = CFrame.new(torso.RightShoulder.C1.Position)* CFrame.Angles(-rx/1.85,0,0)
				rootPart.CFrame =CFrame.new(rootPart.CFrame.p) * CFrame.fromOrientation(0, ry + math.rad(-5) , 0)

				--HOW WOULD I ROTATE ONLY THIS PART ON THE X AXIS SO IT WORKS WITH THE REST OF THE SCRIPT
				waist.C1 = CFrame.new(waist.C1.Position)* CFrame.Angles(-rx/1.8,0,0)
				canaim.Changed:connect(function()
					if canaim.Value == false then

						aim = false
					end
				end)
			end
		end
	end
end)



local goal1 = {C1 = waist.C1*CFrame.Angles(0,0,math.rad(0))}
local goal2 = {C1 = waist.UpperTorso.C1*CFrame.Angles(0,0,math.rad(-5))}
local goal3 = {C1 = waist.UpperTorso.C1*CFrame.Angles(0,0,math.rad(5))}
local info = TweenInfo.new(
	.5,
	Enum.EasingStyle.Quad,
	Enum.EasingDirection.InOut
)
local a = false
local d = false
userInputService.InputBegan:Connect(function(input)
	if canaim.Value == true and aim == true then
		if input.KeyCode == Enum.KeyCode.A then
			a = true
			if a == true and d == true then
				local tween = TweenService:Create(lowerTorso.UpperTorso, info, goal1)
				tween:Play()
			else
				local tween = TweenService:Create(lowerTorso.UpperTorso, info, goal2)
				tween:Play()
			end
		elseif input.KeyCode == Enum.KeyCode.D then
			d = true
			if a == true and d == true then
				local tween = TweenService:Create(lowerTorso.UpperTorso, info, goal1)
				tween:Play()
			else
				local tween = TweenService:Create(lowerTorso.UpperTorso, info, goal3)
				tween:Play()
			end
		end
	end
end)
userInputService.InputEnded:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.A then
		a = false
		if d == false then
			local tween =TweenService:Create(lowerTorso.UpperTorso, info, goal1)
			tween:Play()
		else
			local tween = TweenService:Create(lowerTorso.UpperTorso, info, goal3)
			tween:Play()
		end
	elseif input.KeyCode == Enum.KeyCode.D then
		d = false
		if a == false then
			local tween = TweenService:Create(lowerTorso.UpperTorso, info, goal1)
			tween:Play()
		else
			local tween = TweenService:Create(lowerTorso.UpperTorso, info, goal2)
			tween:Play()
		end
	end
end)
1 Like

do you mean rotate relative to worldspace or object space? In other words do you want it to rotate not relative to itself or relative to itself?

1 Like

no, I am trying to make these two work together at the same time. Like in GTA where the character aims and the uppertorso follows the camera, and when the player moves left to right the Upper torso also move left to right at the same time.

waist.C1 = CFrame.new(waist.C1.Position)* CFrame.Angles(-rx/1.8,0,0)


local goal2 = {C1 = waist.C1*CFrame.Angles(0,0,math.rad(-5))}
local tween = TweenService:Create(lowerTorso.UpperTorso, info, goal2)
				tween:Play()