When you click "z" it is supposed to zoom in This is my first time working with the camera
local zoomMin = 70 -- FOV default local zoomMax = 40 -- FOV zoom in local zoomFrames = 10 -- Larger number = slower zoom speed local zoomWalkSpeedMultiplier = 0.5 -- Slows character down by this factor upon zooming local Cam = game.Workspace.CurrentCamera local canZoom = false playerPlayer = game.Players.LocalPlayer playerCharacter = playerPlayer.Character playerHumanoid = playerCharacter.Humanoid function zoomIn() -- print[[zoomIn()]] isZoomed = true playerHumanoid.WalkSpeed = playerHumanoid.WalkSpeed * zoomWalkSpeedMultiplier for i = 1, zoomFrames do Cam.FieldOfView = Cam.FieldOfView + (zoomMax - Cam.FieldOfView)/3 wait() end Cam.FieldOfView = zoomMax end function zoomOut() -- print[[zoomOut()]] isZoomed = false playerHumanoid.WalkSpeed = playerHumanoid.WalkSpeed for i = 1, zoomFrames do Cam.FieldOfView = Cam.FieldOfView + (zoomMin - Cam.FieldOfView)/3 wait() end Cam.FieldOfView = zoomMin end function commandKeys(key) if key == "z" and canZoom then if not isZoomed then zoomIn() elseif isZoomed then zoomOut() end end end
To define the function, do
... -- after you define "playerPlayer" local mouse = playerPlayer:GetMouse() -- get the player's mouse. ... -- at the end of the code: mouse.KeyDown:connect(function(key) -- connect the function commandKeys(key) -- call your function, and pass the key argument. end)