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

Sword animation Play Error from local scrip and made animation?

Asked by 5 years ago

Hello, I am trying to load an animation by script. This is my LocalScript...

01local CanAttack = true
02 
03script.Parent.Equipped:Connect(function()
04    local AttackL1 = script.AttackAnimationSwordL1
05    local IdleL1 = script.IdleL1
06 
07    IdleL1:Play()
08end)
09 
10script.Parent.Activated:Connect(function()
11    local AttackL1 = script.AttackAnimationSwordL1
12    local IdleL1 = script.IdleL1
13 
14    if CanAttack == true then
15        AttackL1:Play()
View all 24 lines...

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

1Play is not a valid member of Animation
0
hi, may i know which line does the error belong to? guest_20I8 266 — 5y
0
it is different every time but its the lines where I wrote Value:Play() applebugr21 30 — 5y
0
Is there any error for AttackL1:Play() ? Because i think the error is with IdleL1:Play(). guest_20I8 266 — 5y
0
yes both if I keep the sword out it gives me error of IdleL1:Play() and when I click with the sword I get the AttackL1:Play() applebugr21 30 — 5y

1 answer

Log in to vote
0
Answered by
megukoo 877 Moderation Voter
5 years ago

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.
02local humanoid = script.Parent.Humanoid
03local CanAttack = true
04 
05-- Load the animations to be used later
06local AttackL1 = humanoid:LoadAnimation(script.AttackAnimationSwordL1)
07local IdleL1 = humanoid:LoadAnimation(script.IdleL1)
08 
09script.Parent.Equipped:Connect(function()
10    IdleL1:Play()
11end)
12 
13script.Parent.Activated:Connect(function()
14    if CanAttack == true then
15        AttackL1:Play()
View all 24 lines...

If this solves your problem, make sure to accept the answer!

Ad

Answer this question