In my game there is a ‘zoom’ system when right click its held (as with every other FPS game). There is also a binocular tool, with the same feature. However, when zooming in with the binoculars, I can very rarely zoom out - the function designated to un-zooming simply does not fire. However, the rifles zoom in and out perfectly fine, and the code for zooming in and out is almost entirely the same.
mouse.Button2Down:Connect(function()
if equipped == true then
zoom = true
--script.Parent.Zoom:FireServer(true)
print("Zoom in attempted")
holdtrack:Stop()
zoomtrack:Play()
script.Parent.Parent.Zoom.Value = true
GUI.Parent = game.Players.LocalPlayer.PlayerGui
end
end)
mouse.Button2Up:Connect(function()
print("Released right click")
if equipped == true then
GUI.Parent = script.Parent
zoom = false
script.Parent.Parent.Zoom.Value = false
--script.Parent.Zoom:FireServer(false)
print("Zoom out attempted")
zoomtrack:Stop()
holdtrack:Play()
end
end)
This is the code for the binoculars. No errors are displayed, but the second function rarely fires.
mouse.Button2Down:Connect(function()
if equipped == true then
zoom = true
--script.Parent.Zoom:FireServer(true)
print("Zoom in attempted")
holdtrack:Stop()
zoomtrack:Play()
script.Parent.Parent.Zoom.Value = true
end
end)
mouse.Button2Up:Connect(function()
if equipped == true then
zoom = false
script.Parent.Parent.Zoom.Value = false
--script.Parent.Zoom:FireServer(false)
print("Zoom out attempted")
zoomtrack:Stop()
holdtrack:Play()
end
end)
This is the code for the rifle, which functions fine.
I have no doubt that it must be somewhere else in the code or a separate script entirely doing this, because there is no other reason for the code behaving this way. Does anybody have any ideas?