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

How do I make it so I can not have the fov change when the tool is unequipped?

Asked by
D00M1N 4
2 years ago
Edited 2 years ago

I want to make it so the fov won't change when the tool is unequipped, the current script doesn't work, here is my script:

--The whole script doesn't work but if I remove this it works but still does it even if you unequip the tool:
--if tool.Unequipped then
--camera.FieldOfView = 70

local mouse = game.Players.LocalPlayer:GetMouse()
local camera = game.Workspace.CurrentCamera
local tool = script.Parent

mouse.Button2Down:Connect(function() --When you rightclick the fov changes
    camera.FieldOfView = 40
    if tool.Unequipped then --But if it is unequipped it won't change the fov so it stays at 70 (Doesn't work)
        camera.FieldOfView = 70 
    end
end)

mouse.Button2Up:Connect(function() --When you release the right click it will go back to 70
    camera.FieldOfView = 70
end)

This script is being used for a gun I made

1 answer

Log in to vote
0
Answered by
aviel101 165
2 years ago
Edited 2 years ago
local mouse = game.Players.LocalPlayer:GetMouse()
local camera = game.Workspace.CurrentCamera
local tool = script.Parent
local character = game.Players.LocalPlayer.Character

mouse.Button2Down:Connect(function()
    if tool.Parent == character then -- check if player is equipping the tool
        camera.FieldOfView = 40
        local con do
            con = tool.Unequipped:Connect(function() -- wait for tool to be unequipped only once
                camera.FieldOfView = 70
                con:Disconnect()
            end)
        end
    end
end)

mouse.Button2Up:Connect(function()
    if tool.Parent == character then
        camera.FieldOfView = 70
    end
end)
0
Thanks i'll see if that works D00M1N 4 — 2y
Ad

Answer this question