So, essentially, I’ve been making an FPS gun. It’s hard to explain on what my issue is, so I’ll explain it the best I can.
In the code shown in the image, it’s supposed to only aim whilst the gun is equipped; however, even when the gun is unequipped, it’ll still do the aiming part. Weird part is, it doesn’t do it when it’s unequipped at the start, but when I equip the gun then unequip, that’s when the issue starts.
you shouldnt be connecting a function every time the tool is equipped/unequipped. connect it once and then have the equip and unequip events change toolnotequipped and have unequip reset the anims and fov.
local toolnotequipped = true
script.Parent.Equipped:Connect(function()
toolnotequipped = false
end)
script.Parent.Unequipped:Connect(function()
toolequipped = true
idleAnim:Stop()
aimAnim:Stop()
workspace.Camera.FieldOfView = 70
end)
mouse.Button2Down:Connect(function()
if toolnotequipped then return end
idleAnim:Stop()
aimAnim:Play()
workspace.Camera.FieldOfView = 50
end)
mouse.Button2Up:Connect(function()
if toolnotequipped then return end
aimAnim:Stop()
idleAnim:Play()
workspace.Camera.FieldOfView = 70
end)