Why Won't My Animation Play?

I’m trying to make an attack animation play whenever I click with a tool but the animation won’t play. The script is: local remote = script.Parent:WaitForChild(“Handler”) – we store the remote event into a variable
remote.OnServerEvent:Connect(function(Player, Value) – once the remote was firesevered
local character = script.Parent.Parent.Parent – the player’s character
if Value == “Equipped” then – if the string argument wants us to equip the sword then…
print(“equipped”)

	local lookForAnimation = character:FindFirstChild("EquippedAnimation") -- we look for something called "EquippedAnimation" inside the player's character, that will be the equipped animation
	if lookForAnimation then -- if that was found then...
		lookForAnimation:Destroy() --we destroy it
	end

	local animation = Instance.new("Animation", character) --we create a new animation inside of the player's character
	animation.Name = "EquippedAnimation" -- we call it "EquippedAnimation"
	animation.AnimationId = "rbxassetid://7493773366" -- we change its animation id to the equipped animation's id, VERY IMPORTANT YOU NEED TO CREATE UR OWN ANIMATION AND EXPORT IT TO MAKE IT WORK
	local loader = character:WaitForChild("Humanoid"):LoadAnimation(animation) -- we load that animation per humanoid
	loader:Play() -- we play that animation loader

elseif Value == "Unequipped" then
	print("unequipped")

	local animationTracks = character:WaitForChild("Humanoid"):GetPlayingAnimationTracks()
	for _, v in pairs(animationTracks)do
		if v.Name == "EquippedAnimation" then
			v:Stop()
		end
	end

elseif Value == "Attack" then -- if the string argument wants us to attack then...
	print("attack")

	local avaibleAttackAnimations = {7493763859,7493773366} -- a table which contains multiple attack animation ids

	local animation = Instance.new("Animation", character) --we create a new animation inside of the player's character
	animation.Name = "AttackAnimation" -- we call it "EquippedAnimation"
	animation.AnimationId =  "rbxassetid://"..tostring(avaibleAttackAnimations[math.random(1, #avaibleAttackAnimations)]) -- we choose an animation id randomly from that avaiable animations table, VERY IMPORTANT YOU NEED TO CREATE UR OWN ANIMATION AND EXPORT IT TO MAKE IT WORK
	local loader = character:WaitForChild("Humanoid"):LoadAnimation(animation) -- we load that animation per humanoid
	loader:Play() -- we play that animation loader

	script.Parent.Parent.Base.Handle.Touched:Connect(function(hit)
		if hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Name ~= Player.Name and character:FindFirstChild("AttackAnimation") then -- we check if the thing we hit is a npc or a player and does not have the same name as the player has
			if not hit.Parent:FindFirstChild("HitFolder") then
				local f = Instance.new("Folder", hit.Parent)
				f.Name = "HitFolder"
			end
			if not hit.Parent:FindFirstChild("HitFolder"):FindFirstChild(Player.Name) then
				local x = Instance.new("IntValue", hit.Parent:FindFirstChild("HitFolder"))
				x.Name = Player.Name
				game.Debris:AddItem(x, 2)
				local meleeMulti = character:WaitForChild("Melee Multi")
				local meleeBoost = meleeMulti.Value
				hit.Parent.Humanoid:TakeDamage(250 + meleeBoost) -- we make the thing we hit take 10 damage, you can change that 10 to whatever you want
			end
		end
	end)

	wait(1)
	loader:Stop()
	animation:Destroy()
end

end)

Hi there, I think the problem might be that this line:

	animation.AnimationId = "rbxassetid://7493773366" -- we change its animation id to the equipped animation's id, VERY IMPORTANT YOU NEED TO CREATE UR OWN ANIMATION AND EXPORT IT TO MAKE IT WORK

should be

	animation.AnimationId = 7493773366 -- we change its animation id to the equipped animation's id, VERY IMPORTANT YOU NEED TO CREATE UR OWN ANIMATION AND EXPORT IT TO MAKE IT WORK

When I changed the script to what you said it put an error in the output and said it was an invalid id.

I have reviewed through some of your code.
Don’t destroy the animation it will break it and cause it to not work.

Use :Stop(), the animation gets destroyed when you do :destroy()
so it is much better just to use the stop function instead AnimationTrack | Roblox Creator Documentation

animation.AnimationId = "https://www.roblox.com/asset/?id=7493773366"

I tried this and the output said it was an invalid id.

Is it only the attack animation that won’t play or will none of the animations play?

None of the animations will play.

The next points to check are:

  • Do you receive any messages in the output?
  • Does character return properly if you print it after you define it?
  • Are the animations’ priorities set to Action?

I placed the code in an empty game with placeholder animations and it worked for me.

I don’t receive any messages in the output. For the second question I don’t know what it means. And all the priorities are set to action.

If you type print(character) after you define it as script.Parent.Parent.Parent, what do you see in the output? Does it return the name of your character or something else?

It returns the name of my character.

Found the problem, the animation I played is using R6 and I forgot to turn the avatars into r6 so the animations didn’t work… Pretty stupid mistake.