Error - LoadAnimation requires an Animation object

I have no clue why it’s happening, but the code looks fairly normal to me. The object I’m referring to here is a non-humanoid model (uses AnimationController).

Code:

local function Light(Object,Type)
	local ClassObject = nil
	local Animation = nil
	if Object.Name == "LightL" then
		ClassObject = game.Workspace["Core scripts"].Lights.Animations.Left:WaitForChild(tostring(Type))
	elseif Object.Name == "LightR" then
		ClassObject = game.Workspace["Core scripts"].Lights.Animations.Right:WaitForChild(tostring(Type))
	end
	local Animation = Object.AnimationController.Animator:LoadAnimation(ClassObject)
	Animation:Play()
	repeat 
		wait() 
	until LightModeActivated.Value == false
	Animation:Stop()
	coroutine:yield()
end

local connection = task.defer(Light,object,Type)

Error occurs on this line:

(30char)

Could you provide the error itself or if there is any error at all?
EDIT: Oh it’s on title, kinda of a rogue approach to giving the error x_x

Error is listed above.

This line seems to be causing it.

Have you done any debugging such as printing what ClassObject, before the line that is creating the error.

Yes, I have. It properly registers it. The error, however, still persists.

Maybe try actually creating an Instance of the animation through script and loading the animation that way. I know that is quite a length task, but it might reveal more of the problem.

1 Like

Is it really necessary tho? I think the code is fine or there’s something that disrupts it. That shouldn’t really be a barrier.

Does anyone have any other ideas?

the script doesn’t directly target the actual humanoid, its directing to something called “Animator”
fix it so it targets the humanoid directly, not the “Animator”

The object is a non-humanoid object (a LED light). It uses AnimationController instead.

Humanoid is deprecated, this is the new standard to loading animation

I mean it’s worth a try?

function createAnimation(id)
    local x = Instance.new("Animation")
    x.AnimationID = id
    return x
end
-- Written in pseudo so might be inaccurate

It might seem unnecessary, but your setup environment is also very unclear from what you have provided.

i’ve never understood that, am i just being stupid or something?

Update: I gave this a try anyway to see if it would do the job. It ACTUALLY worked! Thanks for recommending this. :laughing:

2 Likes

Well that now reveals that it’s likely just not organised properly, at least your explorer tree.
That’s an assumption, but it would be nice if we can see the Explorer.

1 Like

Try writing “local ClassObject = nil” as “local ClassObject” since what I think is happening, is that the LoadAnimation is prioritizing your first “local ClassObject = nil” while ignoring the other ClassObject.