Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Changing the camera's field of view when you right click not working?

Asked by 5 years ago

Hello! A couple weeks back I made a gun when you hold down right click it plays an animation that you "Zoom in", but I want to change the field of view also when I hold down right click on the script. It does work, but when I release right click it doesn't go back to the normal field of view. It just zooms in whenever I press down right click. It is inside of the handle of the gun. I added little notes to show you where in the script is the change of field of view. Any help would be appreciated! Here is the Local Script:

local mouse = game.Players.LocalPlayer:GetMouse()
local Camera = game.Workspace.Camera
tool = script.Parent.Parent
mouse.Button2Down:Connect(function()
tool.Equipped:connect(function()
    game.Players.LocalPlayer.CameraMode = Enum.CameraMode.LockFirstPerson
Camera.FieldOfView = Camera.FieldOfView - 1.6 --Here is the problem
    local animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.ZoomInAnimation)
     animation:Play()
end)
end)
mouse.Button2Up:Connect(function()
    tool.Equipped:connect(function()
        game.Players.LocalPlayer.CameraMode = Enum.CameraMode.LockFirstPerson
Camera.FieldOfView = Camera.FieldOfView - 1.6 --Here is the problem
local Animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.ZoomOutAnimation)       
Animation:Play()
end)
end)
tool.Unequipped:Connect(function(mouse)
    game.Players.LocalPlayer.CameraMode = Enum.CameraMode.Classic
Camera.FieldOfView = Camera.FieldOfView + 1.6 -- Here is the problem
local player = game.Players.LocalPlayer
    local ActivTracks = player.Character.Humanoid:GetPlayingAnimationTracks()
    for _, v in pairs(ActivTracks) do
        v:Stop()
end
end)
0
'mouse.Button2Down:Connect(function() 05 tool.Equipped:connect(function()' You have the equipped function within the right click function, which could be causing it. Creeperthekid32 70 — 5y

2 answers

Log in to vote
0
Answered by
Arkrei 389 Moderation Voter
5 years ago

Try changing "game.Workspace.Camera" to workspace.CurrentCamera

0
Ok, I'll try it. Mrmonkeyman120 65 — 5y
0
Nope, the same bug is happening, It keeps zooming in. And doesn't zoom out when I do Mouse.Button2Up Mrmonkeyman120 65 — 5y
0
I figured it out, I just needed to change line 15 to "= Camera.FieldOfVeiw + 1.6" Instead of Mrmonkeyman120 65 — 5y
Ad
Log in to vote
0
Answered by 1 year ago
Edited 1 year ago

It's because this code:

14 - game.Players.LocalPlayer.CameraMode = Enum.CameraMode.LockFirstPerson

You need to change the CameraMode to "Classic" here since this is part of the function that runs only when MouseButton2 is released.

14 - game.Players.LocalPlayer.CameraMode = Enum.CameraMode.Classic

Here is it revised. Should work.

Answer this question