I'm trying to make it so that the camera zooms in when the player presses the right mouse button while the tool is equipped. It works for the most part, but the problem is it still works even after I have unequipped the tool. I have a very loose understanding on functions, though if I had to guess, it's because of the mouse connect function within the ADS function. Or maybe there is a way to stop the function in the OnUnequipped function?
function ADS()
local aiming = false
local mouse = game.Players.LocalPlayer:GetMouse()
mouse.Button2Down:connect(function()
aiming = true
for i = 1,5 do
game.Workspace.CurrentCamera.FieldOfView = (70-(i*2))
wait()
end
repeat wait () until aiming == false
end)
mouse.Button2Up:connect(function()
aiming = false
for i = 1,5 do
game.Workspace.CurrentCamera.FieldOfView = (60+(i*2))
wait()
end
end)
end
function OnEquipped(playerMouse)
ADS()
end

1 comment
I found several problems, fixing