How could I rotate an object

So what I made is a cannon which I want to move around and up and down, I’m not really sure how to approach this as this also will need to be able to rotate on a moving platform.

My best guess is CFrame but I don’t know how to use CFrame

You will need to make a script that will tween or CFrame your camera and it will need to rotate you need to do when the up arrow or whatever your using is pressed it need to add +1 to the rotation if the player stopped pressing it it needs to stop that and don’t add an +1 to rotation you will nee to do like this

repeat
	wait(0.01) -- add an delay to not ratate 10000000 speed or crash your PC
	
	-- add the rotate thing here
until -- it needs to repeat until the button is not pressed

Is the cannon Anchored or not?
If it’s Unanchored you can use a HingeConstraint with the AcutatorType set to Motor if you want it to rotate more than 360 degrees, or if you want it to move in a certain arc you can set it to Servo.

If players will be walking over and around the cannon I’d suggest this method since CFraming an Anchored item doesn’t allow players to be moved around with the item if they stand on it, unless you do some extra scripting.

The base of the turret is anchored and everything else is welded to main part and then primarypart, How I want it to work is when you press A or D it will rotate to the left or right through CFrame or anything possible

If It’s a turret, I recommend using Motor6D and keep on setting the DesiredAngle and Target according to the rotation.

Here’s some pseudocode you can use as a reference:

UserInputService.InputBegan:Connect(function(input,IsTyping) -- if he started pressing
if IsTyping then return end -- if the player is typing in chat, ignore the keybind

if input.KeyCode == Enum.KeyCode.D then -- if he pressed D then
Motor6D:SetDesiredAngle(360) -- begin rotation
elseif input.KeyCode == Enum.KeyCode.A then -- but if he pressed A then
Motor6D:SetDesiredAngle(-360) -- begin rotation
end

end)

UserInputService.InputEnded:Connect(function(input) -- when he stopped pressing
if input.KeyCode == Enum.KeyCode.D then -- when he stopped pressing D then
Motor6D:SetDesiredAngle(Motor6d.CurrentAngle)  -- stop the rotating
elseif input.KeyCode == Enum.KeyCode.A then -- when he stopped pressing A then
Motor6D:SetDesiredAngle(Motor6d.CurrentAngle) - stop the rotating
end
end)