Trying to stop an animation from Humanoid

  1. Objective: I’m looking to have a tool with a custom idle animation and a custom animation when activated.

  2. Problem: When trying to remove the animation with tool.Unequipped there is no animation removed.

  3. What solutions have you tried so far? I tried looking at tutorials. However, they have proven themselves not being useful because they have the same or more issues.

local tool = 				script.Parent
local animationActivated = 	tool:WaitForChild("anihit")
local animationIdle =		tool:WaitForChild("anihold")

tool.Equipped:Connect(function()
	local player = 			game:GetService("Players").LocalPlayer
	local character = 		player.Character
	local Humanoid = 		character.Humanoid
	
	local playAnimation = 	Humanoid:LoadAnimation(animationIdle)
	playAnimation:Play()
end)

tool.Activated:Connect(function()
	local player = 			game:GetService("Players").LocalPlayer
	local character = 		player.Character
	local Humanoid = 		character.Humanoid
	
	local hitAnimation = 	Humanoid:LoadAnimation(animationActivated)
	hitAnimation:Play()
end)

tool.Unequipped:Connect(function()
	local player = 			game:GetService("Players").LocalPlayer
	local character = 		player.Character
	local Humanoid = 		character.Humanoid
	
	local playAnimation = 	Humanoid:LoadAnimation(animationIdle)
	playAnimation:Stop()
end)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

1 Like

in the tool unequipped you are making another variable of animation that doesnt have anything to do with the one you are playing when equipping.

Do this instead

local tool = 				script.Parent
local animationActivated = 	tool:WaitForChild("anihit")
local animationIdle =		tool:WaitForChild("anihold")


tool.Equipped:Connect(function()
	local player = 			game:GetService("Players").LocalPlayer
	local character = 		player.Character
	local Humanoid = 		character.Humanoid
	
	playAnimation = Humanoid:LoadAnimation(animationIdle)
	playAnimation:Play()
end)

tool.Activated:Connect(function()
	local player = 			game:GetService("Players").LocalPlayer
	local character = 		player.Character
	local Humanoid = 		character.Humanoid
	
	local hitAnimation = 	Humanoid:LoadAnimation(animationActivated)
	hitAnimation:Play()
end)

tool.Unequipped:Connect(function()
	local player = 			game:GetService("Players").LocalPlayer
	local character = 		player.Character
	local Humanoid = 		character.Humanoid
	
	playAnimation:Stop()
end)

i made your playAnimation variable global, so that it can be used outside of tool.equipped function, and in unequipped instead of loading another animation, we are stopping the one that is already loaded and playing

2 Likes

Thanks a lot for the info! It works as intended now

I know its solved but even if it error’s it wont effect anything inside the script. Just keep that in mind for future projects