Hello, I am trying to load an animation by script. This is my LocalScript...
01 | local CanAttack = true |
02 |
03 | script.Parent.Equipped:Connect( function () |
04 | local AttackL 1 = script.AttackAnimationSwordL 1 |
05 | local IdleL 1 = script.IdleL 1 |
06 |
07 | IdleL 1 :Play() |
08 | end ) |
09 |
10 | script.Parent.Activated:Connect( function () |
11 | local AttackL 1 = script.AttackAnimationSwordL 1 |
12 | local IdleL 1 = script.IdleL 1 |
13 |
14 | if CanAttack = = true then |
15 | AttackL 1 :Play() |
For some reason I get this error message and the script doesn't work. This is a scrpit that I found on youtube of 2017 so it might be outdated but I don't think Play() is I need help fixing this scrpit. this is the error message I get
1 | Play is not a valid member of Animation |
The problem with your script is that you haven't loaded the Animations yet. Animations are required to be loaded in order for them to be played.
You can do this using Humanoid:LoadAnimation()
01 | -- This is assuming your Script is inside a Tool object. |
02 | local humanoid = script.Parent.Humanoid |
03 | local CanAttack = true |
04 |
05 | -- Load the animations to be used later |
06 | local AttackL 1 = humanoid:LoadAnimation(script.AttackAnimationSwordL 1 ) |
07 | local IdleL 1 = humanoid:LoadAnimation(script.IdleL 1 ) |
08 |
09 | script.Parent.Equipped:Connect( function () |
10 | IdleL 1 :Play() |
11 | end ) |
12 |
13 | script.Parent.Activated:Connect( function () |
14 | if CanAttack = = true then |
15 | AttackL 1 :Play() |
If this solves your problem, make sure to accept the answer!