#camera zoom speed gets progressively faster every time i equip and unequip a tool for no reason.

49 messages · Page 1 of 1 (latest)

honest olive
#

Your Z not zooming out when tapping problem is probably due to the fact that you subtract in your first bit there:

if camera.FieldOfView >= maxzoom  then
  return
else
  camera.FieldOfView = camera.FieldOfView - zoomspeed
  task.wait(0.002)
end

should probably be:

if camera.FieldOfView >= maxzoom  then
  return
else
  camera.FieldOfView = camera.FieldOfView + zoomspeed
  task.wait(0.002)
end
#

Is zoomspeed modified in any other parts of the rest of the script?

wary maple
#

ohh okay

wary maple
#
uis.InputBegan:Connect(function(key, gameProcessedEvent)
        if gameProcessedEvent then return end

        if key.KeyCode == Enum.KeyCode.Z then
            if camera.FieldOfView >= maxzoom then
                return
            else

                camera.FieldOfView = camera.FieldOfView + zoomspeed
                task.wait(0.002)
            end
        end

        while uis:IsKeyDown(Enum.KeyCode.Z) do
            task.wait(0.002)
            camera.FieldOfView = camera.FieldOfView + zoomspeed
            if camera.FieldOfView >= minzoom then
                break
            end
        end

    end)
    
    
    uis.InputBegan:Connect(function(key, gameProcessedEvent)
        if gameProcessedEvent then return end
        
        if key.KeyCode == Enum.KeyCode.X then
            if camera.FieldOfView <= maxzoom then
                return
            else
                
                camera.FieldOfView = camera.FieldOfView - zoomspeed
                task.wait(0.002)
            end
        end

        while uis:IsKeyDown(Enum.KeyCode.X) do
            task.wait(0.002)
            camera.FieldOfView = camera.FieldOfView - zoomspeed
            if camera.FieldOfView <= maxzoom then
                break
            end
        end

    end)
#

see

#

i changed it and the z tap problem still isnt working

honest olive
#

Lemme try and emulate this without the rest of the parts lol. Sometimes it's better to get the whole picture. Gimme a few

wary maple
#

its cause i put maxzoom instead of minzoom

#

but the second problem still exists

#

and yeah im not changing zoomspeed anywhere else

honest olive
#

Hmm.. I would wonder if the while loop is somehow running multiple times...

oblique mortarBOT
#

studio** You are now Level 2! **studio

wary maple
#

hmm

wary maple
#

its being broken when the zoom limit is met

honest olive
#

Hmm. Is it maybe due to the fact that you're binding InputBegan for both zoom out and in keys?

#

Oh!

#

Hold on I think I got it...

#

Every time you equip the tool it binds the methods AGAIN

wary maple
honest olive
#

And then you end up running the same code multiple times, because the number of bindings keeps increasing. It's multiplying it

wary maple
#

binds the keys?

honest olive
#

uis.InputBegan:Connect(function(key, gameProcessedEvent)

wary maple
#

ohh

honest olive
#

These get run every time you equip the tool lol

wary maple
#

so how do i remove that binding when i unequip it?

wary maple
honest olive
#

You have to disconnect them on the unequip I guess

#

Or find some other way to handle the input

#

Uhh lemme see. I never actually disconnected an event binding before

wary maple
#

huh

wary maple
honest olive
#

So declare the binding as a variable and call :Disconnect() on that variable... Lemme cook something up...

wary maple
#

local bind = uis eihihw

#

and then

#

bind:Disconnect()

#

?

#

YES

honest olive
#

YEah something like that

wary maple
#

IT WORKS

wary maple
honest olive
#

Noice 🙂 👍

wary maple
#

imma delete this post now

honest olive
#

No, thank you. I leaarned some things lol

wary maple
#

lmao

#

cya