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)