Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer
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)

1 comment

0

Thanks i'll see if that works

This discussion is preserved as it was. New answers, comments, and votes are closed.