Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why does animation still play when tool unequips?

I want to make it where when i equip a tool a animation plays, and when i unequip it, the animation should stop. When i unequip it, the animation still plays.

help

local Tool = script.Parent
local Animation = Tool.Animation





Tool.Equipped:Connect(function()
	
	local Player = Tool.Parent
	local Humanoid = Player.Humanoid
	local Animator = Instance.new("Animator")

	local AnimationPlay = Humanoid.Animator:LoadAnimation(Animation)

	AnimationPlay:Play()

	
end)


Tool.Unequipped:Connect(function()
	
	local Player = Tool.Parent
	local Humanoid = Player.Humanoid
	local Animator = Instance.new("Animator")


	local AnimationPlay = Humanoid.Animator:LoadAnimation(Animation)

	AnimationPlay:Stop()
	
end)

1 answer

instead of:

local AnimationPlay = Humanoid.Animator:LoadAnimation(Animation)

AnimationPlay:Stop()

try:

for i,child in pairs(Humanoid:GetPlayingAnimationTracks()) do
 if child.Animation.AnimationId == “rbxasset//insert_animation_id” then
  child:Stop()
 end
end

hopefully it works out :D

This discussion is preserved as it was. New answers, comments, and votes are closed.