Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

"LoadAnimation requires an Animation object." Error message?

I have skimmed over this code and made elaborations and so on for the past three hours, and I have finally caved in to asking you big-brained people for assistance. Below is my code for two punch animations:

local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:wait()
local tool = script.Parent
local swingsound = tool:WaitForChild("Swing")
local canattack = tool:WaitForChild("CanAttack")
local Punch1 = Instance.new("Animation")
Punch1.AnimationId = "rbxassetid://4921775472"
local Punch2 = Instance.new("Animation")
Punch2.AnimationId = "rbxassetid://4921778051"

tool.Activated:connect(function()
	local choose = math.random(1,2)
	canattack.Value = true
	if choose == 1 then
		local swing1animation = script.Parent.Parent.Humanoid:LoadAnimation(script.Punch1)
		swingsound:Play()
		swing1animation:Play()
	elseif choose == 2 then
		local swing2animation = script.Parent.Parent.Humanoid:LoadAnimation(script.Punch2)
		swingsound:Play()
		swing2animation:Play()
	end
end)

tool.Deactivated:connect(function()
	canattack.Value = true
end)

tool.Unequipped:connect(function()
	local hum = char:WaitForChild("Humanoid")
	for _,anim in pairs(hum:GetPlayingAnimationTracks()) do
 		anim:Stop()
	end
end)

Now, before you ask, yes, the two animations are named (respectively) "Punch1" and "Punch2." They also are not Animations, but rather AnimationTracks. I really appreciate any insight you all can provide.

2 comments

0

what's the point in defining Punch1 and Punch2 and then not using them in LoadAnimation lol

0

It was one of the random "Last Stand" attempts at trying to get this thing to work

1 answer

For those of you referencing this due to a similar issue, all I did to fix it was delete the "script." in the parenthesis of the animation. I hope this helped you :)

2 comments

0

Hello, sorry to be so late but only "script"? Or the whole paranthesis. I am going to guess script.

0

Didn't work. :(

This discussion is preserved as it was. New answers, comments, and votes are closed.