mouse.KeyDown:connect(function(key) if key == "R" then NewTurret.Orientation = Vector3.new(X0,Y+90,Z0) end end)
You asked: How do I make this rotate on key down R?
Firstly, we must use the UserInputService which can detect user input via the keyboard.
local UIS = game:GetService("UserInputService"); UIS.InputBegan:Connect(function(key, gpe) if (not gpe) then if (key.KeyCode == Enum.KeyCode.R) then NewTurret.CFrame = NewTurret.CFrame * CFrame.Angles(0,math.rad(90),0); end end end)
This will rotate the turret 90 degrees on the Y axis. Always use CFrame.Angles() when dealing with rotation. In my example I'm assuming NewTurret is a part, or an object that has a CFrame. If it's a model you could use
local UIS = game:GetService("UserInputService"); UIS.InputBegan:Connect(function(key, gpe) if (not gpe) then if (key.KeyCode == Enum.KeyCode.R) then NewTurret:SetPrimaryPartCFrame(NewTurret.PrimaryPart.CFrame * CFrame.Angles(0,math.rad(90), 0)); end end end)
Although when using the provided code above you must have the primary part set already on the model. math.rad() takes an argument in degrees and converts it to radians which is what CFrame.Angles() uses.
Maybe??
local UIS = game:GetService('UserInputService') UIS.InputBegan:Connect(function(key,gpe) if key.KeyCode == Enum.KeyCode.R and not gpe then local NewTurret = workspace.Part -- Remove this since you already have a variable for it NewTurret.Orientation = Vector3.new(X,Y+90,Z) end end)