Animation playing problem

I am trying to stop the animation when the tool is unequipped.

image
image

It works normally, but if you unequip the tool while the equip animation is playing, you will get stuck in the idle animation. (that plays right after equip animation)

I’d like to hear suggestions on how I could resolve this problem.

Here is a sample of my code:

local reloadAnimationPreload = player.Character:FindFirstChild("Humanoid").Animator:LoadAnimation(animations:WaitForChild("Reload"))
local idleAnimationPreload = player.Character:FindFirstChild("Humanoid").Animator:LoadAnimation(animations:WaitForChild("Idle"))
local holsterAnimationPreload = player.Character:FindFirstChild("Humanoid").Animator:LoadAnimation(animations:WaitForChild("Holster"))
local fireAnimationPreload = player.Character:FindFirstChild("Humanoid").Animator:LoadAnimation(animations:WaitForChild("Fire"))
local equipAnimationPreload = player.Character:FindFirstChild("Humanoid").Animator:LoadAnimation(animations:WaitForChild("Equip"))

local findAmmoGui

local function equip()
	local duplicate = gui:Clone()
	duplicate.Parent = player.PlayerGui
	findAmmoGui = player.PlayerGui:FindFirstChild("GlockAmmoGui")
	sounds.Equip:Play()
	weaponModule.onEquip()
	equipAnimationPreload:Play()
	findAmmoGui.MainFrame.AmmoLeft.Text = ammo
	findAmmoGui.MainFrame.MaxAmmo.Text = maxAmmo
	wait(equipAnimationPreload.Length)
	equipAnimationPreload:Stop()
	idleAnimationPreload:Play()
	game.StarterPack:SetAttribute("running", true)
end

local function unequip()
	weaponModule.onUnequip()
	weaponModule.unAim()
	findAmmoGui = nil
	reloadAnimationPreload:Stop()
	idleAnimationPreload:Stop()
	holsterAnimationPreload:Stop()
	fireAnimationPreload:Stop()
	equipAnimationPreload:Stop()
	game.StarterPack:SetAttribute("running", false)
end
2 Likes

I am having this exact same issue. My character just gets stuck into the animation once it plays. Very frustrating!

1 Like

try using a print statement if its unequipd
check if the parent changed maybe?

Someone helped me solve this problem days ago. You have to create your own animation for it to start and stop properly, it isn’t just handed to you

1 Like

What do you exactly mean by this?

I fixed the issue by adding an “if” check if the tool is equipped and the GUI is parented. Then I added a few animation-related lines to it and it works perfectly now.

Basically in conclusion, if you equipped the gun and the equip animation was still playing while you unequipped the gun the idle animation would then start playing (even without the weapon being equipped)

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