So I am making a weapons system within my game and I need to be able to "aim down" sights when the player holds the right mouse button.
Here is what I have so far:
UIS.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton2 then
held = true
-- mouse button2 is being heldown
if game.Players.LocalPlayer.Character:FindFirstChild(script.Parent.Name) then
while held == true do
if (cam.CFrame.p - cam.Focus.p).Magnitude < 0.6 then
--- checks if player is in first person
isAiming = true
local currentCamera = workspace.CurrentCamera
local startPos = script.Parent.FirstPersonViewPart
currentCamera.CameraType = Enum.CameraType.Follow
currentCamera.CameraSubject = startPos
currentCamera.Focus = startPos.CFrame
--- sets the camera's position to the FirstPersonViewPart's position
else
currentCamera.CameraSubject = game.Players.LocalPlayer.Character.Humanoid
-- if player let go of button2 it will return the camera to default
end
game:GetService("RunService").RenderStepped:Wait()
end
end
end
end)
I am looking for something like this: https://www.youtube.com/watch?v=92fSHmz03Jw
- I don't care if it's a smooth transition or not
But the result I am getting is that the camera rotates around the FirstPersonViewPart when the player tries to look around while aimed in.

1 comment
I believe the problem is because your startPos is the FirstPersonViewPart, and you set the camera's focus to the part's cframe which is why you are getting this error