Animations still going on while tool is unequipped / Aim animation not stopping

I have been recently working on a ROBLOX Over The Shoulder Gun System, but I got a little problem, whenever I aim/take a tool that is a weapon, animations still work even if the tool is unequipped.

local player = game.Players.LocalPlayer

local ContextActionService = game:GetService("ContextActionService")

local connection

local RunService = game:GetService("RunService")

local UserInputType = game:GetService("UserInputService")

local mouse = player:GetMouse()

repeat wait(1) until player.Character

local Char = player.Character

local hum = Char:WaitForChild("Humanoid")

local AnimHold = script.Parent.AnimationsFolder.Idle_Anim

local AnimTrackHold = hum:LoadAnimation(AnimHold)

local AnimAim = script.Parent.AnimationsFolder.Aim_Anim

local AnimTrackAim = hum:LoadAnimation(AnimAim)

local aiming = false

script.Parent.Equipped:Connect(function(Mouse)
	AnimTrackHold:Play()
	mouse.Button2Down:Connect(function()
		connection = RunService.RenderStepped:Connect(function()
			AnimTrackAim:Play()
			AnimTrackHold:Stop()
			mouse.Button2Up:Connect(function()
				connection:Disconnect()
				AnimTrackAim:Stop()
				AnimTrackHold:Play()
			end)
		end)
	end)
end)

script.Parent.Unequipped:Connect(function()
	AnimTrackHold:Stop()
	AnimTrackAim:Stop()
end)

That’s the script I have made mixing the DevForum and YouTube Tutorials.

Just in case, look at a video I am going to send.Animations Issue

1 Like

I think I have fixed it anyway.

1 Like