Simple animation script not functioning

Right so I have a script (the one below), which is a localscript inside of the tool.

local tool = script.Parent
local player = game.Players.LocalPlayer
local anim = script:FindFirstChild("slash")
local cooldown = false



tool.Activated:Connect(function()
	print("on")
	if cooldown == false then
		local humanoid = player.Character:FindFirstChild("Humanoid")
		local animation = humanoid:LoadAnimation(anim)
		animation:Play()
		cooldown = true
		wait(2)
		cooldown = false
	end
end)

It gives the error LoadAnimation requires an animation object.

Its a local script the line is fine, its something else

Are you sure about that script founded local player?

That was the orginal attempt, it didn’t work either so i switched to this.

Are you sure that “anim” is an Animation object as created by the explorer*, and not a KeyframeSequence or other sort of object?

not sure, can you tell me what the instance is called?

What is the output of print(anim.ClassName) ? Additionally, are you sure that the animation exists at the time of running? You may need to use :WaitForChild(“slash”) rather than :FindFirstChild(“slash”)

This is what it looks like image

I just made the animation, it says that I tried to find the classname of nil

It appears that your usage of :FindFirstChild() is resulting in the code searching for the animation before it actually exists on the client. Switch Line 3 to:

local anim = script:WaitForChild("slash")

, and that will (most likely) resolve your issue.

Thanks, this fixes one issue, the animation itself isn’t working now but this is good progress (no more errors)

Is there anything Ive done wrong that wouldn’t play the animation? (Importance is set to movement)

Ensure that you have set the Priority of the animation to be higher than Core (and most likely to the highest priority, Action.) To do this, open the animation in the Animation Editor, click the three dots, mouse over Set Animation Priority, and then click on Action. After that, export your animation again and overwrite the prior one.

I also assume that the animation you are playing is owned by you. If it is uploaded to a group that you have developer access to, try playing the game in the player to see if the animation plays. Animations are a bit finicky in this regard as of the last time I used it in a group, though I may be incorrect.

1 Like

I’m really not sure what’s happened, I just made an anim in studios and exported it, is it then attached to me or the group? (it was made in a different place than the main game)

By default, it is owned by you, unless you changed the ownership to a group while exporting it.

Does this mean that I can use it in other games not directly made by me?

If it is owned by you and it is a group game, the animation will only work in Studio.

Try using print Commands. I’m guessing “anim” is nil. Using FindFirstChild is bad, as it doesn’t return a error if it’s not there, so try using WaitForChild for those things instead.

As you upload an animation, in the box where you can write the name/description of the animation, you’ll be able to see a Creators dropdown menu that defaults to “Me”. If you click on the drop down, it should list the groups that you have permission to upload assets to.

1 Like