Why won't this change the players camera to the aim part?

I’m trying to make it so my gun system “aims in” when you hold right click. I’m attempting to do this by switching the player’s camera to the aim part attached to the tool.

It’s not working obviously, but I also need to make it so it checks if your in first person, and if you are then you can aim in.

Here is the portion of the script that aims in. It’s most likely obvious whats wrong, but I haven’t really messed with cameras much yet.

--Aiming in
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local Character = player.Character or player.CharacterAdded:Wait()
local camera = workspace.CurrentCamera
local tool = script.Parent

camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = tool.AimPart.CFrame
camera.CameraType = Enum.CameraType.Custom

Thanks! :smile: I’m also wondering if there is away to “smoothly” switch one camera to the part, instead of it just immediately changing.

If you’re making an ADS or scope system, a much more realistic and overall simpler way to do this would be to change the camera’s FieldOfView instead. This can be modified without messing around with camera CFrames and types.

As for checking if the player is in first person or not, you should use DistanceFromCharacter with the camera’s position as the “point” argument.
Example: if player:DistanceFromCharacter(camera.CFrame.p) < .5 then

To make the transition smoother, try using TweenService.

Could you give us some more information on which part of the script isn’t working? What solutions have you tried? Are you getting any errors? Perhaps send a video showing what it’s doing wrong?

1 Like