You can’t use the “Attach” type, you have to use “Scriptable”. Here’s the code I’m using for the game I’m currently working on. It’s probably not quite what you’re doing, but you should be able to adapt it easily enough:
05 | local userInputService = game:GetService( "UserInputService" ) |
06 | local runService = game:GetService( "RunService" ) |
08 | local player = game:GetService( "Players" ).LocalPlayer |
09 | local camera = game:GetService( "Workspace" ).CurrentCamera |
11 | local character = player.Character |
12 | local head = character:WaitForChild( "Head" ) |
13 | local playerPos = head.Position |
15 | local cameraRotation = Vector 2. new( 0 ,math.rad(- 60 )) |
16 | local cameraOffset = CFrame.new( 12 , 20 , 0 ) |
18 | camera.CameraType = Enum.CameraType.Scriptable |
21 | runService.RenderStepped:Connect( function () |
22 | if character and playerPos then |
24 | playerPos = head.Position |
26 | local startCFrame = CFrame.new(playerPos)*CFrame.Angles( 0 , cameraRotation.X, 0 ) |
28 | local camPos = startCFrame:ToWorldSpace(cameraOffset) |
30 | camera.CFrame = CFrame.new(camPos.Position, playerPos) |
31 | camera.Focus = CFrame.new(playerPos) |
32 | camera.CameraSubject = head |
39 | local pressed = userInputService:IsMouseButtonPressed(Enum.UserInputType.MouseButton 2 ) |
42 | userInputService.MouseBehavior = Enum.MouseBehavior.LockCurrentPosition |
44 | local rotation = userInputService:GetMouseDelta() |
45 | cameraRotation = cameraRotation + rotation * math.rad(. 25 ) |
48 | userInputService.MouseBehavior = Enum.MouseBehavior.Default |
53 | userInputService.InputBegan:Connect(input) |
54 | userInputService.InputChanged:Connect(input) |
55 | userInputService.InputEnded:Connect(input) |
So what this does is first script the camera to be updated every frame, but only adjusts it by the X value of the camera rotation, not the Y value. It then sets up the InputService to listen for the right mouse button to be pressed and then records the amount the mouse moves to be turned into an equivalent camera rotation.
Depending on where you want your camera to view from, you just have to change the CFrame of your camera.