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

What is wrong with this zoom script?

Asked by
Mystdar 352 Moderation Voter
10 years ago

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
0
Probably a sign (arithmetic) error in your for loops. Tkdriverx 514 — 10y
0
To me, your not calling 'commandKeys' anywhere in the code, so, it's not going to run. :P Ya Silly Billy. :P TheeDeathCaster 2368 — 10y
0
So just commandkey(key) at the end, right? Mystdar 352 — 10y
0
I assumed you called the function at the end of the script and just didn't include it. Check my answer. Tkdriverx 514 — 10y

1 answer

Log in to vote
0
Answered by
Tkdriverx 514 Moderation Voter
10 years ago

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)
Ad

Answer this question