This right click to zoom in script for my gun won’t work. There’s just an end that is red and won’t go away, and I don’t know how to fix it.
local gun = script.Parent
--UserInputService Setup
local userInput = game:GetService('UserInputService')
--Mouse setup
local mouse = game.Players.LocalPlayer:GetMouse()
mouse.Button2Down:Connect(function()
local camera = game.Workspace.CurrentCamera
camera.FieldOfView = 40
end)
mouse.Button2Up:Connect(function()
local camera = game.Workspace.CurrentCamera
camera.FieldOfView = 70
end
end
end)
You have an unneeded end
here, remove it. And add )
after the second end
.
local gun = script.Parent
--UserInputService Setup
local userInput = game:GetService('UserInputService')
--Mouse setup
local mouse = game.Players.LocalPlayer:GetMouse()
mouse.Button2Down:Connect(function()
local camera = game.Workspace.CurrentCamera
camera.FieldOfView = 40
end)
mouse.Button2Up:Connect(function()
local camera = game.Workspace.CurrentCamera
camera.FieldOfView = 70
end)
how come it works even if the tool isn’t equipped?
You don’t have anything in your code to check if the tool is equipped or not
the code isn’t really mine, because I don’t know how to script well, so how would I do that?
local gun = script.Parent
--UserInputService Setup
local userInput = game:GetService('UserInputService')
--Mouse setup
local mouse = game.Players.LocalPlayer:GetMouse()
local isEquipped = false -- variable to check if the tool is equipped
gun.Equipped:Connect(function()
isEquipped = true
end)
gun.Unequipped:Connect(function()
isEquipped = false
end)
mouse.Button2Down:Connect(function()
if not isEquipped then
return
end
local camera = game.Workspace.CurrentCamera
camera.FieldOfView = 40
end)
mouse.Button2Up:Connect(function()
if not isEquipped then
return
end
local camera = game.Workspace.CurrentCamera
camera.FieldOfView = 70
end)
1 Like