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

what to do when getting error "LoadAnimation requires an AnimationObject"?

i'm trying to make a tool that plays an animation when you click, but when i test it, it errors

script:


local anim = nil 
local cool = script.Parent

function onActivated()
    
    if not cool.Enabled then 
        return 
    end
    cool.Enabled = false

    local character = cool.Parent
    local humanoid = character:WaitForChild("Humanoid")

    if not humanoid then
        return 
    end

    anim = humanoid:LoadAnimation(script.Parent.chomp) 
    if anim then
        anim:Play()
        wait(0.1)
		cool.Enabled = true
    
    end

end

cool.Activated:connect(onActivated)

the error in question appears at line 18 and the code is in a normal script (not a localscript). the object "chomp" is an animation that is inside the tool. what confuses me is that even though it says that LoadAnimation() requires an animationobject, chomp is an animationobject. i'm not sure why this happens bc "anim = humanoid:LoadAnimation()" has worked fine until now

1 answer

Try if this works:

local Animation = Instance.new("Animation")
Animation.AnimationId = "chomp animation id"
local Track = nil 

local cool = script.Parent

function onActivated()
	if not cool.Enabled then return end
	cool.Enabled = false 

	local character = cool.Parent
	local humanoid = character.Humanoid

	Track = humanoid:LoadAnimation(Animation)
	Track:Play()

	wait(0.1)

	cool.Enabled = true 
end

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