Animation not working no matter what

I created an animation and I want it to activate when a tool is equipped. Everything about the tool works fine, it is just that the animation does not play when I equip the tool. I have overlooked my code and my animation and I am almost certain everything is in place.

One odd thing that I found though is if I insert the tool with the script into another place of mine, it works perfectly. So, for some odd reason, this will just not work in the actual game I want it to work in.

Also, something important I should mention is that both places in question and the animation is owned by me. The place I want it to work in is a team create, but I am still the owner. Maybe I did not search well enough, but I could not find anyone else with this isuse.

Here is the code I have in the tool. It is in a LocalScript.

local tool = script.Parent
local player = game.Players.LocalPlayer
local anim = tool:WaitForChild("Animation")

tool.Equipped:Connect(function()
	local char = player.Character
	local huma = char:WaitForChild("Humanoid")
	local animator = huma:FindFirstChildOfClass("Animator") or Instance.new("Animator", huma)
	local PlayAnim = animator:LoadAnimation(anim)
	PlayAnim:Play()
end)

1 Like
  1. You should load animations at the start of your script. Reusing animation tracks can save memory.
  2. Have you tried using a server script?
  3. Using the second parameter of Instance.new() to set the parent is memory inefficient. Could you try removing that “safety net”? I would just like to see if the script can find the animator.
  4. Could you add debug print statements to ensure that the animation-playing code is actually being reached?
3 Likes
  1. Okay, I understand that.
  2. I have and It still does not work.
  3. I removed the Instance.new() and (this goes along with 4.) using debug prints, it said that it is still able to find Animator. Also, speaking of the other debug prints, everything else seemed to work well as far as I know. Though, the animation still does not play.
1 Like

Alright. Could you try changing the animation priority? At the top of the script where you load the animation, could you just add the following code in:

PlayAnim.Priority = Enum.AnimationPriority.Action4
3 Likes

Okay, I figured it out. Apparently in avatar settings I needed to make my game R6 only. (since my animation is in R6.) I thought that changing the animation pack to R6 sets the game to R6 but I guess I was wrong.
Thanks for your help anyways.

3 Likes

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