Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago
Edited 5 years ago

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

Log in to vote
0
Answered by
hellmatic 1523 Moderation Voter
5 years ago

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
Ad

Answer this question