Tools animation won't stop when the tool is unequiped

So I want my animation to stop when the tool is unequiped but it doesn’t. The script is a server script inside of the tools Handle.

Here is my code:

script.Parent.Parent.Unequipped:Connect(function()
	local Character = script.Parent.Parent.Parent.Parent.Character
	local Humanoid = Character.Humanoid
	local AnimationTrack = Humanoid:LoadAnimation(Animation)
	AnimationTrack:Stop()
end)
1 Like

You are loading a new animation to the humanoid, and stopping the new animation, not the animation that was loaded when the tool was equipped. Could you show your full script?

1 Like

Yes here it is: (It will be a free model)

--Script and model made by MRBOGO_YT.  Please give credit if you use this!

--Variables

local tweenservice = game:GetService("TweenService")
local Blade1 = script.Parent.Blade1
local Blade2 = script.Parent.Blade2
local Blade3 = script.Parent.Blade3
local Debounce = false

local Info = TweenInfo.new(
	0.4,
	Enum.EasingStyle.Sine,
	Enum.EasingDirection.Out,
	0,
	false,
	0
)

local Goals1 = {
	Size = Vector3.new(4.65, 0.2, 0.15)
}

local Goals2 = {
	Size = Vector3.new(0.747, 0.158, 0.133)
}

local Goals3 = {
	Size = Vector3.new(0.747, 0.158, 0.133)
}

--On/off script

script.Parent.Parent.Equipped:Connect(function()
	wait(0.3)
	Blade1.Size = Vector3.new(0.001, 0.2, 0.15)
	Blade1.Transparency = 0
	Blade1.PointLight.Enabled = true
	Blade2.Size = Vector3.new(0.007, 0.158, 0.133)
	Blade2.Transparency = 0
	Blade2.PointLight.Enabled = true
	Blade3.Size = Vector3.new(0.007, 0.158, 0.133)
	Blade3.Transparency = 0
	Blade3.PointLight.Enabled = true
	local Tween1 = tweenservice:Create(Blade1, Info, Goals1)
	local Tween2 = tweenservice:Create(Blade2, Info, Goals2)
	local Tween3 = tweenservice:Create(Blade3, Info, Goals2)
	Tween1:Play()
	Tween2:Play()
	Tween3:Play()
end)

script.Parent.Parent.Unequipped:Connect(function()
	wait(0.1)
	script.Parent.Blade1.Transparency = 1
	script.Parent.Blade1.PointLight.Enabled = false
	script.Parent.Blade2.Transparency = 1
	script.Parent.Blade2.PointLight.Enabled = false
	script.Parent.Blade3.Transparency = 1
	script.Parent.Blade3.PointLight.Enabled = false
end)

--Sounds

local Sound1 = script.Parent["Ahsoka saber sound."]
local Sound2 = script.Parent["Ahsoka Saber Hum"]
local Sound3 = script.Parent.saber_swing2
local Sound4 = script.Parent["Ahsoka saber disignite"]

script.Parent.Parent.Equipped:Connect(function()
	Sound4:Stop()
	Sound1:Play()
	wait(6)
	Sound1:Stop()
	Sound2.Volume = 2
	Sound2:Play()
end)

script.Parent.Parent.Unequipped:Connect(function()
	Sound1:Stop()
	Sound2:Stop()
	Sound2.Volume = 0
	Sound4:Play()
	wait(1)
	Sound4:Stop()
end)

script.Parent.Parent.Activated:Connect(function()
	Sound3:Play()
end)

--Animations

local Animation = script.Animation
local Animation2 = script.Animation2

script.Parent.Parent.Equipped:Connect(function()
	local Character = script.Parent.Parent.Parent
	local Humanoid = Character.Humanoid
	local AnimationTrack = Humanoid:LoadAnimation(Animation)
	AnimationTrack:Play()
end)

script.Parent.Parent.Unequipped:Connect(function()
	local Character = script.Parent.Parent.Parent.Parent.Character
	local Humanoid = Character.Humanoid
	local AnimationTrack = Humanoid:LoadAnimation(Animation)
	AnimationTrack:Stop()
end)

script.Parent.Parent.Activated:Connect(function()
	local Character = script.Parent.Parent.Parent
	local Humanoid = Character.Humanoid
	local AnimationTrack2 = Humanoid:LoadAnimation(Animation2)
	AnimationTrack2:Play()
end)

--Damage Script
local CanHurt = false

script.Parent.Parent.Activated:Connect(function()
	CanHurt = true
end)

script.Parent.Parent.Deactivated:Connect(function()
	wait(0.4)
	CanHurt = false
end)

script.Parent.Blade1.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") and not Debounce and CanHurt then
		local Humanoid = hit.Parent.Humanoid
		Humanoid:TakeDamage(100)
		Debounce = true
	elseif Debounce then
		wait(0.5)
		Debounce = false
	end
end)
1 Like

Okay, I didnt know your script was that long. I am only going to make changes to the Equipped and Unequipped functions.

You want to make an empty variable at the start of the script. Then when someone equips the tool, you want to make the variable equal to the the animation that you want to play when tool is equipped. And then when the tool is unequipped, you can easily just mention the variable name, and then stop the animation by using :Stop function.

Replace this full code:

--Animations

local Animation = script.Animation
local Animation2 = script.Animation2

script.Parent.Parent.Equipped:Connect(function()
	local Character = script.Parent.Parent.Parent
	local Humanoid = Character.Humanoid
	local AnimationTrack = Humanoid:LoadAnimation(Animation)
	AnimationTrack:Play()
end)

script.Parent.Parent.Unequipped:Connect(function()
	local Character = script.Parent.Parent.Parent.Parent.Character
	local Humanoid = Character.Humanoid
	local AnimationTrack = Humanoid:LoadAnimation(Animation)
	AnimationTrack:Stop()
end)

With this updated code:

--Animations

local Animation = script.Animation
local Animation2 = script.Animation2
local AnimationTrack -- leaving this blank

script.Parent.Parent.Equipped:Connect(function()
	local Character = script.Parent.Parent.Parent
	local Humanoid = Character:WaitForChild("Humanoid")
	AnimationTrack = Humanoid:LoadAnimation(Animation) --  makes the variable non-empty
	AnimationTrack:Play()
end)

script.Parent.Parent.Unequipped:Connect(function()
	local Character = script.Parent.Parent.Parent.Parent.Character
	local Humanoid = Character:WaitForChild("Humanoid")
	AnimationTrack:Stop() -- just putting 'Stop()' because variable is not blank
end)
3 Likes

Wow… I didn’t know it was that simple… Thanks!

2 Likes

No problem! Happy to help :smiley: 30 letters

2 Likes