Gun animation wont play, How do I fix it?

Hey! I am making a gun (Using a tool) where once the player holds down the right mouse button the camera zooms in and the character plays an animation. But when the player lets go of the mouse button the animation should stop. I dont know how to make it stop the animation and I have been trying for hours… Does anyone know what im doing wrong or how to fix this?

Here is my code, please help me out!

local Tool = script.Parent --make sure this is a Tool object
local Camera = game.Workspace.CurrentCamera
local Player = game.Players.LocalPlayer -- this also only works in LocalScripts
local Character = workspace:WaitForChild(Player.Name)
local Humanoid = Character:WaitForChild("Humanoid")

local Animation = Instance.new("Animation") -- create a new animation object
Animation.AnimationId = "rbxassetid://5446362077" -- put your animation id over the zeroes
local Track = Humanoid:LoadAnimation(Animation)

zooming = false


					

Tool.Equipped:Connect(function(Mouse)
	Mouse.Button2Down:Connect(function()
		print("Button1Down")
		
		zooming  = true
		Camera.FieldOfView = 70
		wait()
		Camera.FieldOfView = 57
		wait()
		Camera.FieldOfView = 55
	

	Mouse.Button2Up:Connect(function()
			print("Button2Down")
			
			zooming = false
			
			Camera.FieldOfView = 55
			wait()
			Camera.FieldOfView = 57
			wait()
			Camera.FieldOfView = 70
			
			if zooming == true then
				
				Track:Play()
				
				if zooming == false then
					
					Track:Stop()
					
				end
			end
			
			
			end)
	end)
end)
2 Likes

I believe you’re only supposed to have the ID and not that other stuff so just 5446362077.

I tried that it says invalid animation id

Pretty simple to stop an animation, just do Animation:Stop()

Did you make the animation? If so check your ID cause the one I found was by someone named SOlo470. You need to upload the animation your self for any animation to work seeing as you cannot make them to where you can buy them.

https://www.roblox.com/library/5446362077/FireHold

Edit: I’ve Died the creator of this topic and they say that they’re scripting on their alt and not their main where the animation is located. This is why the error is occurring. Switch to the main account for the animation to work.

Yes I am on my alt account using some of the models I have made on that one

i already did that

30characters

I am im just posting the problem on this account

I am working in that account already the problem isnt the animation its the code thats still not working!

1 Like

Instead of checking if ‘zooming’ is true, maybe make it so when you press the right mouse button, it plays the animation, and when you release the button, it stops the animation? Like so:

Tool.Equipped:Connect(function(Mouse)
	Mouse.Button2Down:Connect(function()
		print("Button1Down")
		
		zooming  = true
		Camera.FieldOfView = 70
		wait()
		Camera.FieldOfView = 57
		wait()
		Camera.FieldOfView = 55
	Track:Play()

	Mouse.Button2Up:Connect(function()
			print("Button2Down")
			
			zooming = false
			
			Camera.FieldOfView = 55
			wait()
			Camera.FieldOfView = 57
			wait()
			Camera.FieldOfView = 70
			Track:Stop()
		
			end
			
			
			end)
	end)
end)

YES! That was it Thank you!

30characters