Animation still plays even after unequipped

The normal animations are good, its what happens when you click E and then unequip the weapon. It still plays the weapons animation.

I’ve tried for hours to fix this and it hasn’t worked. I’m looking for outside help.
There no errors.
Printing “K” is to show I clicked ’ E ’

local players = game.Players.LocalPlayer
local anim1 = script.Parent.Animation
local anim2 = script.Parent.FireAnimation

local anim = script.Parent.Rest

local camera = game.Workspace.CurrentCamera


local track
local track2
local trackA

local UIS = game:GetService("UserInputService")

local CanFire = false

script.Parent.Equipped:Connect(function()

	track = players.Character.Humanoid:LoadAnimation(anim1)
	track:play()
end)

script.Parent.Unequipped:Connect(function()
	trackA = players.Character.Humanoid:LoadAnimation(anim)
	track:stop()
	trackA:stop()
end)

local debouce = false

script.Parent.Activated:Connect(function()
	if debouce == false then
		debouce = true
		track2 = players.Character.Humanoid:LoadAnimation(anim2)
		track2:play()
		camera.CFrame = camera.CFrame * CFrame.Angles(.005,math.rad(.5),0)
		wait(.01)
		camera.CFrame = camera.CFrame * CFrame.Angles(.0015,math.rad(.8),0)
		wait(.01)
		camera.CFrame = camera.CFrame * CFrame.Angles(.002,math.rad(.5),0)
		wait(.01)
		camera.CFrame = camera.CFrame * CFrame.Angles(-.0015,math.rad(0),0)
		wait(.01)
		camera.CFrame = camera.CFrame * CFrame.Angles(-.005,math.rad(0),0)
		wait(.01)
		camera.CFrame = camera.CFrame * CFrame.Angles(-.002,math.rad(0),0)

		debouce = false
	end
end)

local Temp = false

UIS.InputBegan:Connect(function(key)
	if script.Parent then
		if key.KeyCode == Enum.KeyCode.E then

			if Temp == false then
				Temp = true
				print("K")
				trackA = players.Character.Humanoid:LoadAnimation(anim)
				trackA:play()
			elseif Temp == true then
				Temp = false
				trackA:stop()
			end
		end
	end
end)
4 Likes

Does stopping track2 in the function connected to Unequipped solve the issue?

Some other things I noticed:

  1. Loading animations on the Humanoid is deprecated. Load it on the Animator instead.
  2. You only have to load the animation once.
  3. In the function connected to the Unequipped event, why are you stopping trackA right after you load it.
1 Like

Thank you, I used the animator and stopped track2 which fixed it.

Glad to hear that your issue is resolved. Please mark my previous reply as a solution if it helped!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.