2 animation limit? (LoadAnimation requires an Animation object error)

I wrote a script on a gun holding animation and today i added another local script that plays an animation upon shooting. The holding animation worked before but now it gives me the error "LoadAnimation requires an Animation object " on line 14

carryTrack = animator:LoadAnimation(carryAnim)

I have no clue whats wrong as everything was working before. Is there a two animation limit? Any help is appreciated

4 Likes

mind showing the animation in explorer?

1 Like

what is animator defined as? can you show some more of the script as well?

1 Like

the animator is build into humanoids so you could just do:

local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")

local walkAnim = hum:LoadAnimation(WALK)

i had the same problem initially, just remember this and you are good to play 90% of all animations :+1:

3 Likes

image

2 Likes
local carryTrack = nil

local function doAnimations(char, equipped)
	local hum = char:WaitForChild("Humanoid")
	local animator = hum:WaitForChild("Animator")

	if equipped then
		carryTrack = animator:LoadAnimation(carryAnim)
		carryTrack:Play()
	elseif carryTrack then
		carryTrack:Stop()
		carryTrack:Destroy()
	end```
the main animator part of the script
2 Likes

where is doAnimations being called? Also add a print right above LoadAnimation, what’s the output?

print(animator)

2 Likes

do animations is called a bit lower
image
after adding the print it says "attempt to index nil with ‘Disconnect’ "

3 Likes

change connection:Disconnect()

if connection then
   connection:Disconnect()
end

then change
local hum = char:WaitForChild("Humanoid")
local hum = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")

2 Likes

It solved the first issue but it still says this, which was my original problem

2 Likes

what’s the output for the print(animator)

2 Likes

“function doAnimations”
“function onEquipped”
Its in blue so its not an error

2 Likes

thats the stack trace, i’m asking for what it says when you add the print(animator) before loading the animation

2 Likes

The animation automatically loads when you equip the tool

1 Like

I don’t think you understand how LoadAnimation() works, the animation has to be an object like a Animation Instance like a part or a humanoid not an ID.

1 Like

I found the problem, I had both of the animations set to action. I just changed the bolt animation to action2

1 Like

Yo, I know you solved this, but I’m just saying, don’t use an animator, trust me. You need an animationController and it’s a whole thing, so just use the Humanoid:LoadAnimation() thing i talked about in post 4

1 Like

Alr i’ll keep that in mind for the future.

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