Load animation requires an animation object

i dont think I did this right…
I’m making a sword system where every time you click the next animation plays, so a new sword animation per click.

I get an error message stating load animation requires animation object.

This is what I did, it is erroring at line 29

local tool = script.Parent

local player = game.Players.LocalPlayer

local debounce



local event = game.ReplicatedStorage.Swing

local animz = script.Parent.Anims

local hum = player.Character:WaitForChild("Humanoid")

local animator = hum:FindFirstChildOfClass("Animator")

local anims = {
	animz.Swing1,
	animz.Swing2,
	animz.Swing3
}



tool.Activated:Connect(function()
	debounce = true
	if debounce == true then
		for index,animation in ipairs(anims) do
			anims[index] = animator:LoadAnimation(animation)  track
			local anim = animator:LoadAnimation(animation)
			event:FireServer(anim)
			wait(.25)
			debounce = false
		end
		
	
	end
end)

So what I believe is going on that when you first activate the tool, you won’t get the error because you’re loading new animations into the humanoid. But once you click <1 times, then you are trying to load the same animations in with the same name.

What I would do here is not set the debounce to true every time it activates, but instead set it to true at the top of the script, and then in the activated script you can have like a counter that every time they click, it will play the next animation. Something like this

Edit: I’m not sure what the remote event does, but if it just fires the animation you don’t really need that as it replicates across the server.

local AnimCount = 1
tool.Activated:Connect(function()
	if debounce == true then
		for index,animation in ipairs(anims) do
			anims[index] = animator:LoadAnimation(animation)  track
			local anim = animator:LoadAnimation(animation)
			event:FireServer(anim)
			wait(.25)
			debounce = false
		end
	end
    anims[AnimCount]:Play()
    AnimCount = AnimCount + 1
    if AnimCount == 4 then
        AnimCount = 1
    end
end)
1 Like

Well using this it doesnt work and this errors:

Play is not a valid member of Animation “Workspace.trueblockhead101.OldSword.Anims.Swing1”

I did my best and tried to replicate how you did it. I removed the remote event part just because it didn’t seem to impact anything one way or another.

The only way I was getting your error was if I had removed the for loop, but other than that it worked fine.

1 Like

Well the error is coming from this line

anims[AnimCount]:Play()

And it is weird because it is returning the correct animation but for some reason the animation can be played according to the error…

Okay let’s see if a different way works.

Instead of using a for loop, just remove that. And instead load the animations in the table. So the table should look like this:

local anims = {
	animator:LoadAnimation(animz.Swing1),
	animator:LoadAnimation(animz.Swing2),
	animator:LoadAnimation(animz.Swing3)
}

and then the Activated function will be left looking like this:

tool.Activated:Connect(function()
	anims[AnimCount]:Play()
	AnimCount = AnimCount + 1
	if AnimCount == 4 then
		AnimCount = 1
	end
end)
1 Like

Alright this is what I did:

local anims = {
	animator:LoadAnimation(animz.Swing1),
	animator:LoadAnimation(animz.Swing2),
	animator:LoadAnimation(animz.Swing3)
}


tool.Activated:Connect(function()

	if debounce == true then
		debounce = false
		
		anims[AnimCount]:Play()
		AnimCount = AnimCount + 1

		if AnimCount == 4 then
			AnimCount = 1
		end

		wait(.25)
		debounce = true

	end	

end)

And there is an error message line under [AnimCount] plus it stating that it sees :Play() as nil again.

The error message line under [AnimCount] is telling me to make the function it is in local.

local animz = script.Parent.Anims

local hum = player.Character:WaitForChild(“Humanoid”)

The only other thing I can think is to change those two lines above to this.

local animz = script.Parent:WaitForChild("Anims")

local character = player.Character or player.CharacterAdded:Wait()

local hum = character:WaitForChild("Humanoid")

Ya doesnt change the outcome, send me the full script that you used to create the video you sent. I’ll try to edit that and see if that works, or it may be just something up with my studio file or how my explorer is set up…

local tool = script.Parent

local player = game.Players.LocalPlayer

local debounce = true




local animz = script.Parent:WaitForChild("Anims")

local character = player.Character or player.CharacterAdded:Wait()

local hum = character:WaitForChild("Humanoid")

local animator = hum:FindFirstChildOfClass("Animator")

local anims = {
	animz.Swing1,
	animz.Swing2,
	animz.Swing3
}
local AnimCount = 1

tool.Activated:Connect(function()
	if debounce == true then
		for index,animation in ipairs(anims) do
			anims[index] = animator:LoadAnimation(animation)
			local anim = animator:LoadAnimation(animation)
			wait(.25)
			debounce = false
		end
	end
	anims[AnimCount]:Play()
	AnimCount = AnimCount + 1
	if AnimCount == 4 then
		AnimCount = 1
	end
end)

Yeah it might be how its set up. Mine is set up with the tool in starterpack, and then a folder called “Anims” with all the animations parented to it. And then the local script and the handle.

Ya same yet mine is in the workspace which could be affecting the local script.

Ok well I set it up to how mine is configured but I still get that error:

LoadAnimation requires an Animation object 

yet swing1 - swing3 are animation objects!

You don’t happen to have any animations with the same names in your Anims folder do you?

Nope, they all have different names…