So I want to make a Animation play when you are equipped a gun and it plays an animation for your character to make the gun zoom in closer to get better aim. Everything works fine, but when you unequip the gun the animation just keeps playing? I tried many things like:
local anim = game.Players.LocalPlayer.Character.Humanoid(script.Parent.ZoomOutAnimation)
anim:Stop()
end
But for some reason it stil doesn't work.. Here is the LocalScript that is inside of the Handle of the gun. The two animation names are..ZoomInAnimation, and ZoomOutAnimation
local mouse = game.Players.LocalPlayer:GetMouse()
tool = script.Parent.Parent
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()
tool.Unequipped:Connect(function(mouse)
game.Players.LocalPlayer.CameraMode = Enum.CameraMode.Classic
local anim = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(ZoomInAnimation)
anim:Stop()
Hopefully you can help! I thought this is pretty easy, but I have no idea why nothing is working!! Anything helps ;) -Mrmonkeyman120

4 comments
@Mrmonkeyman120 cus u didnt tell it to stop the right wae
Can you elaborate how I actually tell it to stop the RIGHT way? -Thanks!
make sure that you have some sort of way to tell if the item is in the players inventory/equipped before playing the animation
Yeah, I thought I need something like that. Mabye I could use ""if animation = Equiped then"? I'm not sure..