LoadAnimation Requires Animation Object

“Before anyone says to research the site about my problem before posting, i literally did that and their issues are not like mine.”

I’m currently working on a punch combo but whenever i try to play a punch animation, it shows the error "LoadAnimation Requires Animation Object.

This is my coding:

local function Punch_Combo(Character)
	local Combo = Character:GetAttribute("Combo")
	if Combo >= MAX_PUNCHCOMBO then
		Character:GetAttribute("Combo", 1)
	else
		Character:GetAttribute("Combo", Combo + 1)
	end
end

local function GetPunch_ANIMATION(Character)
	local Combo = Character:GetAttribute("Combo")
	local Punch_Animations = RS_Storage:WaitForChild("Animations"):WaitForChild("Combat"):WaitForChild("Punches"):GetChildren()
	
	local Current_PunchAnimation = Punch_Animations[Combo]
	return Current_PunchAnimation
end

local function Stop_ANIMATIONS(Animation_Object)
	for i, v in pairs(Animation_Object:GetPlayingAnimationTracks()) do
		v:Stop()
	end
end

--- Remote Events ---
Remote_Events.Punch_Event.OnServerEvent:Connect(function(Player)
	local Player_Character = Player.Character or Player.CharacterAdded:Wait()
	local Character_Humanoid = Player_Character:WaitForChild("Humanoid")
	local CH_Animator = Player_Character:WaitForChild("Humanoid"):WaitForChild("Animator")
	local CH_RootPart = Player_Character:WaitForChild("HumanoidRootPart")
	local Attacking = Player_Character:GetAttribute("Attacking")
	local Punching = Player_Character:GetAttribute("Punching")
	
	if Attacking or Punching then 
		return 
	end
	
	Player_Character:SetAttribute("Attacking", true)
	Player_Character:SetAttribute("Punching", true)
	
	Punch_Combo(Player_Character)
	Stop_ANIMATIONS(CH_Animator)
	GetPunch_ANIMATION(Player_Character)
	
	local PlayPunch_Animation = CH_Animator:LoadAnimation(GetPunch_ANIMATION(Player_Character))
	
	PlayPunch_Animation.KeyframeReached:Connect(function(KF)
		if KF == "Hit" then
			Player_Character:SetAttribute("Attacking", false)
			if Player_Character:GetAttribute("Combo") == MAX_PUNCHCOMBO then
				task.wait(1)
			end
			Player_Character:SetAttribute("Punching", false)			
		end
	end)
	
	PlayPunch_Animation:Play()
	
end)

The script error when ever i try to play the "PlayPunch_Animation" variable
image

I would appreciate it if anyone could help me fix this issue. i’ve been trying to find a solution for an hour on this issue but no luck.

1 Like

Hey, Try to add a print on line 216 printing the parameters you’re passing to LoadAnimation and show what you get

2 Likes

image
After printing the parameters

There you go, That’s your issue! You are not getting an animation to begin with. The Problem is not with LoadAnimation but the fact that you are trying to do LoadAnimation(nil) which means load nothing

1 Like

If i may ask, is there a way to load this animations in? I know other methods but i want to hear what you think is best to do

I would suggest you load all the possible animations on the players animator in variables and use those animation tracks as many times in whatever way you want. You don’t really have to clone and load it every time (I think there’s also a limit to how many you can load maybe 256).

Working on something else rn but something like

local Anim1 = Instance.new("Animation")
Anim1.AnimationId = "rbxassetid://2312314124" --> You can Also just store Animation Instances with Ids in ReplicatedStorage and clone those

local Animator = humanoid:FindFirstChildOfClass("Animator")
local Anim1Tracks = Animator:LoadAnimation(Anim1)
local Anim2Tracks = Animator:LoadAnimation(Anim2)

--> When you Need them
Anim1Tracks:Play()

1 Like

Thanks for the help!! I owe you one.

1 Like

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