Ok, so I'm making a gun that when you press down the right button a animation plays and moves your gun closer to you for better aim. It works, but when I unequipped the gun, the animation plays when I right click. I have this script so it checks that you are equipped to the gun before you can play the gun (Line 3) I really need help!! Anything helps! Here is the script:
local mouse = game.Players.LocalPlayer:GetMouse()
tool = script.Parent.Parent
if tool.Activated then
tool.Equipped:connect(function()
game.Players.LocalPlayer.CameraMode = Enum.CameraMode.LockFirstPerson
mouse.Button2Down:Connect(function()
local animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.ZoomInAnimation)
animation:Play()
end)
end)
mouse.Button2Up:Connect(function()
local Animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.ZoomOutAnimation)
Animation:Play()
if tool.Deactivated then
tool.Unequipped:Connect(function(mouse)
game.Players.LocalPlayer.CameraMode = Enum.CameraMode.Classic
local player = game.Players.LocalPlayer
function StopAnimations()
local ActivTracks = player.Character.Humanoid:GetPlayingAnimationTracks()
for _, v in pairs(ActivTracks) do
v:Stop()
end
end
end)
end

1 comment
tool.Activated only happens after tool.Equipped so remove line 3