Problem with animations

hello guys so im loading an animation from a module script, but the third animation does not play, and instead i get the error “LoadAnimation requires an Animation Object”, assuming this error means that the 3rd animation is nil

the animations:

local animations = game:GetService("ReplicatedStorage"):WaitForChild("Animations")
local idles = animations.Idles

local katana, war, naginata = animations.Katana, animations.Warhammer, animations.Naginata

return {
	
	Katana = {
		
		katana.A1;
		katana.A2;
		katana.A3;
		
	};
	
	Warhammer = {
		
		war.A1;
		war.A2;
		war.A3;
		war.A4;
		war.A5;
		
	};
	
	Naginata = {
		
		naginata.A1;
		naginata.A2;
		naginata.A2;
		naginata.A3;
		naginata.A4;
		
	};
	
	Idles = {
		
		Katana = idles.Katana;
		Warhammer = idles.Warhammer;
		Naginata = idles.Naginata;
		
	};
	
}

heres the function

function handler:M1_Client()

	local character = game.Players.LocalPlayer.Character

	local weapon = character:FindFirstChild("Loadout"):WaitForChild("Weapon")
	local name = handler:get_name(weapon)
	local blade = weapon:FindFirstChild("Blade")

	self.clean = trove.new()
	
	local c = 0
	
	uis.InputBegan:Connect(function(input, gpe)
		if input.UserInputType == Enum.UserInputType.MouseButton1 and not gpe then
			if is_equipped == true and state_debounce == false then
				state_debounce = true
				c += 1
				if c == 3 then
					c = 0
				end
				
				character:FindFirstChild("Humanoid"):LoadAnimation(animations.Katana[c]):Play()
				
				
				task.wait(0.8)
				state_debounce = false
			end
		end
	end)
end

idk why the animation in the 3rd index is not playing
plz help

instead of findfirstchild you need to wait for the child.

local Humanoid = Character:WaitForChild("Humanoid")
local Animator = Humanoid:WaitForChild("Animator")
local Track = Animator:LoadAnimation(animations.Katana[c])
Track:Play()

does not work
i alr tried chaining up a bunch of waitforchild()s

The error you’re getting “LoadAnimation requires an Animation Object” is the game trying to tell you that youre trying to run LoadAnimation on a nil (non existant) object. This means that you need to wait until the object exists before you can continue.

There could be many issues with your script however, there’s a lot of code and you will probably need to do more scanning to see what kind of typos or errors you didn’t notice.

the thing is i wrote this entire script yesterday and it worked perfectly however when i was working on new stuff today this error started to show up

idk what happened but i didnt even touch the M1_client() function

its a recurring problem
the final index in the other 2 animation tables does not load as well

You should instead try something along the lines of this, i’ve made combo chains before and I think maybe you should give it a try:

local ComboNum = 1
local MaxClicks = 3
local TimeSinceLastClick

local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local Animator = Humanoid:WaitForChild("Animator")

local Animations = {
	["Katana"] = {
		game.ReplicatedStorage.AnimationsFolder.Katana.Animation1,
		game.ReplicatedStorage.AnimationsFolder.Katana.Animation2,
		game.ReplicatedStorage.AnimationsFolder.Katana.Animation3,
	};
}

local function playAnimation()
	local Animation = Animations["Katana"][ComboNum]
	local Track = Animator:LoadAnimation(Animation)
	Track:Play()
end

local function clicked()
	playAnimation()
	if (ComboNum + 1 > MaxClicks) or (TimeSinceLastClick and tick() > TimeSinceLastClick + .8) then
		ComboNum = 1
	else
		ComboNum += 1
	end
	TimeSinceLastClick = tick()
end

The main issue you’re having is that your combo has a 0 value that is possible to be indexed. It’s likely a bug, so maybe you could try setting it to 1 instead of 0 and alternatively making it so it adds to the combo after playing the animation.

This script will not work it’s just a demonstration on how you can do things

1 Like

i’ll take reference from ur script, thanks for the help amigo

1 Like

hey, just an update! i fixed the issue, i was trying to find an animation of index [0] which was the main issue! thanks for the help :smile:

1 Like