(FIXED)Animation isn't playing

Greetings!

I’ve been scripting for a month now,
and seemed to run into a Animation script problem.

So, this script is in a tool that you purchase in a shop.
Problem being that when I use the tool, it doesn’t seem to play the animation. I checked related problems on the devforum, but didn’t find any. This script was half done by a comrade and guided me to an extent, but he never had a stop feature.

(The script did play before I added the stop feature, however, even after the tool was unequipped, it continued to play the animation.)

This is where and how it is set up in studio
image

SCRIPT IN “Script_Animations” BELOW

local Player = game:GetService("Players")
local Local_Player = Player.LocalPlayer


script.Parent.Equipped:Connect(function()
	local Char = Local_Player.Character or Local_Player.CharacterAdded:Wait()
	Char:WaitForChild('Humanoid'):LoadAnimation(script:WaitForChild("Idle")):Play()
end)
script.Parent.Equipped:Connect(function()
	local Char = Local_Player.Character or Local_Player.CharacterAdded:Wait()
	Char:WaitForChild('Humanoid'):LoadAnimation(script:WaitForChild("Idle")):Stop()
end)

script.Parent.Activated:Connect(function()
	local Char = Local_Player.Character or Local_Player.CharacterAdded:Wait()
	if script:WaitForChild("Type").Value == 1 then
		script:WaitForChild("Type").Value = 3
		Char:WaitForChild('Humanoid'):LoadAnimation(script:WaitForChild("AniAttack")):Play()
		script:WaitForChild("Swoosh"):Play()
		wait(1)
		script:WaitForChild("Type").Value = 2
	elseif script:WaitForChild("Type").Value == 2 then
		script:WaitForChild("Swoosh"):Play()
		script:WaitForChild("Type").Value = 3
		Char:WaitForChild('Humanoid'):LoadAnimation(script:WaitForChild("AniAttack")):Play()	
		wait(1)
		script:WaitForChild("Type").Value = 1
		end
	end)
	script.Parent.Unequipped:Connect(function() -- This is where I added the stop function
		if Char then
		Char:Stop()
		end
end)

How do I fix this so that when the player equips the tool, it starts the animation given. And when the player unequips the tool, it’ll stop the animation.

Thank you for your assistance!

Replace

script.Parent.Equipped:Connect(function()
	local Char = Local_Player.Character or Local_Player.CharacterAdded:Wait()
	Char:WaitForChild('Humanoid'):LoadAnimation(script:WaitForChild("Idle")):Stop()
end)

With:

script.Parent.Unequipped:Connect(function() --When player unequips the tool
	local Char = Local_Player.Character or Local_Player.CharacterAdded:Wait()
	for _, v in pairs(Char:WaitForChild("Humanoid"):GetPlayingAnimationTracks()) do --Loops through the playing animations in the humanoid
		if v.Name == "Idle" then
			v:Stop() --Stops the animation if it is "Idle"
		end
	end
end)

This SHOULD fix the problem, but if there are any issues let me know.

It does play the animation, however it still doesn’t stop the animation when the tool is unequipped.
(Still no errors regarding animation or the script)

Yes, the script that I sent should stop the animation when the player unequips the tool.

It doesn’t though. Could this still be an error in the script or in the animation itself? (Apologies, I don’t work with animations)

Is the animation uploaded to the game owner?

If the game is under your name, upload it to yourself, or if it"s under a group, upload it to your group

I’m not sure, but I think you are supposed to load the animations at the beginning of your script, then just play them, not load them each and every time the function is called.

I don’t know if this is what’s causing the animation stopping issue though.
Hang on, you have 2 Equipped Functions, but no Unequipped Function…

script.Parent.Equipped:Connect(function()
	local Char = Local_Player.Character or Local_Player.CharacterAdded:Wait()
	Char:WaitForChild('Humanoid'):LoadAnimation(script:WaitForChild("Idle")):Play()
end)
script.Parent.Equipped:Connect(function()
	local Char = Local_Player.Character or Local_Player.CharacterAdded:Wait()
	Char:WaitForChild('Humanoid'):LoadAnimation(script:WaitForChild("Idle")):Stop()
end)

So when it’s Equipped, it depends which one gets called. If the first one is called, it won’t call the second one, which is basically stopping the animation.

I found the problem.
If you click to fast, the animation will constantly play even after unequipping the tool.
I fixed this, but Thank you everyone who helped!!

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