Hiya,
I'm having a little bit of a problem with animations. I've only recently started working with them as most of my work up until this point has been UI/backend systems based and so I've never had a reason to learn about them before.
I've got the actual animating down to a tee, however getting the animations to play is a different story. Here's the code I'm currently using to attempt to play an Idle animation on tool equip:
local player = game:GetService("Players").LocalPlayer local humanoid = player.Character.Humanoid local animations = {} for i, v in pairs(script:GetChildren()) do if v:IsA("Animation") then animations[v.Name] = humanoid:LoadAnimation(v) end end script.Parent.Equipped:connect(function() animations["Idle"]:Play() end)
This doesn't work and produces the following error message on tool equip:
22:27:21.048 - LoadAnimation requires the Humanoid object (TheOIdRepubIic.Humanoid.Animator) to be in Game 22:27:21.048 - Stack Begin 22:27:21.048 - Script 'Players.TheOIdRepubIic.Backpack.Lightsaber.AnimationHandler', Line 7 22:27:21.049 - Stack End
However, the following code does work:
local player = game:GetService("Players").LocalPlayer script.Parent.Equipped:connect(function() local animations = {} for i, v in pairs(script:GetChildren()) do if v:IsA("Animation") then animations[v.Name] = script.Parent.Parent.Humanoid:LoadAnimation(v) end end animations["Idle"]:Play() end)
In general I really don't like having to use the workaround given in the second example because it means I'm having to rely on the tool being in the player's character model as opposed to pre-loading the animations in the backpack.
Does anyone have a solution, or at least a more bearable workaround, for this?
Any help is appreciated.
3tianne
P.S. Forgot to mention this is being run in a local script - a friend of mine told me that animations are OK to be dealt with client side. I haven't bothered to check whether that's the problem but I'm assuming it's not seeing as the animations load fine in the second example.