Help with rotating the player's camera

Hello, I’ve been trying to make the player’s camera rotate when strafing.
However, it does not work. Here is the code;

service = game:GetService("UserInputService")
service.InputBegan:Connect(function(key)
	if key.KeyCode == Enum.KeyCode.A then
		workspace.CurrentCamera.CFrame.Rotation = CFrame.fromOrientation(15, 0, 0)
	end
end)
service.InputEnded:Connect(function(key)
	if key.KeyCode == Enum.KeyCode.A then
		workspace.CurrentCamera.CFrame.Rotation = CFrame.fromOrientation(0, 0, 0)
	end
end)

When I would play test the code, this would show up in the output
image

It would look like this:

service = game:GetService("UserInputService")
service.InputBegan:Connect(function(key)
	if key.KeyCode == Enum.KeyCode.A then
		workspace.CurrentCamera.CFrame = CFrame.new(workspace.CurrentCamera.CFrame.Position) * CFrame.fromOrientation(15, 0, 0)
	end
end)
service.InputEnded:Connect(function(key)
	if key.KeyCode == Enum.KeyCode.A then
		workspace.CurrentCamera.CFrame = CFrame.new(workspace.CurrentCamera.CFrame.Position) * CFrame.fromOrientation(0, 0, 0)
	end
end)

You can’t directly change the rotation of the CurrentCamera.

1 Like

Thanks a bunch! This will definitely help me with anything camera related.

local Game = game
local Workspace = workspace
local UserInput = Game:GetService("UserInputService")
local Camera = Workspace.CurrentCamera

UserInput.InputBegan:Connect(function(Input, GameProcessed)
	if GameProcessed then return end
	if Input.KeyCode == Enum.KeyCode.A then
		Camera.CFrame = CFrame.new(Camera.CFrame.Position) * CFrame.fromOrientation(15, 0, 0)
	end
end)

UserInput.InputEnded:Connect(function(Input, GameProcessed)
	if GameProcessed then return end
	if Input.KeyCode == Enum.KeyCode.A then
		Camera.CFrame = CFrame.new(Camera.CFrame.Position)
	end
end)