Animation Plays but wont Stop

I’m trying to make the animation return to Roblox’s default animations (idle animation) when unequipping the tool.

When my code runs, the output prints “AnimWorked2” meaning the script executed correctly without errors, but the animation doesn’t “stop” and return to default rblx animations.

I’ve tried another method which came out with an error; but this one didn’t. I’ve scoured forums and rblx scripting documentation on trying to stop the animation or even to destroy it, but it doesn’t seem to work.

My animation I’m playing is looped and is replicated from replicated storage, then played onto the character’s animator as an “Idle” animation holding up boxing gloves.
(It’s a server script btw)

local gloveIdle = repStorage.Animations.Gloves.PresetAnimations.GloveIdle:Clone()

tool.Equipped:Connect(function()
	local char = tool.Parent
	if char:WaitForChild("Left Arm") ~= nil then
		local weldClone = grip:Clone() -- This is welding dont worry about this
		weldClone.Parent = char:WaitForChild("Left Arm")
		weldClone.Part0 = weldClone.Parent
		weldClone.Part1 = tool.Handle2
		weldClone.C0 = weldClone.C0*CFrame.new(0,-1,0)
		char:WaitForChild("Humanoid").Animator:LoadAnimation(gloveIdle):Play() -- Animation Plays on character when tool is equipped.
		print("AnimWorked")
	end
end)

tool.Unequipped:Connect(function()
	local char = tool.Parent.Parent.Name -- This is the players name unequuipping the tool
	for i, v in pairs(game.Workspace:GetChildren()) do
		if v.Name == char then
			v:WaitForChild("Humanoid").Animator:LoadAnimation(gloveIdle):Stop()
			print("AnimWorked2")
		end
	end
end)
1 Like

You’re reloading the animation into the Animator. Make a reference to the AnimationTrack instead:

local gloveIdle = char:WaitForChild("Humanoid").Animator:LoadAnimation(gloveIdle)

For the animation for equipping the tool try setting the animation priority higher than the core ones, try each priority apart from the core priority because thats the same priority as the default animations and is the lowest priority.

I’m a bit confused. Is my local variable wrong, should I be referencing it differently? It’s also a server script.

I’ve already done that, since the animation works on equipping. The issue is unequipping the tool.

You load the animation Here in the .Equipped connection

and then reload it when unequipping, this wont work since it creates a new AnimationTrack. Instead reference your AnimationTrack using:
gloveIdle = char:WaitForChild("Humanoid").Animator:LoadAnimation(gloveIdle)

If this is a server script, you can get a reference to the player the moment the tool gets put into the players Backpack using

local Tool = script.Parent --Assuming this is the tool
local Backpack = Tool.Parent
local Player = Backpack.Parent

I’m not quite sure if I understand. Wouldn’t that just make the code error, since the variable is being changed?
(I’m really sorry for being a pain, this is my first time handling animations :joy:)

I tried this, but it didn’t work:

tool.Unequipped:Connect(function()
	local char = tool.Parent.Parent.Name -- This is the players name unequipping the tool
	for i, v in pairs(game.Workspace:GetChildren()) do
		if v.Name == char then
			gloveIdle:Destroy()
			print("AnimWorked2")
		end
	end
end)

you have to use :Stop() to stop an animation.

You never create a variable for gloveIdle, thats your issue. You’re creating a NEW AnimationTrack by using :LoadAnimation() inside your Unequipped connection

Oh my, thank you so much! That makes sense now.

1 Like

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