Hello, I am trying to load an animation by script. This is my LocalScript...
local CanAttack = true script.Parent.Equipped:Connect(function() local AttackL1 = script.AttackAnimationSwordL1 local IdleL1 = script.IdleL1 IdleL1:Play() end) script.Parent.Activated:Connect(function() local AttackL1 = script.AttackAnimationSwordL1 local IdleL1 = script.IdleL1 if CanAttack == true then AttackL1:Play() IdleL1:Stop() wait(1) CanAttack = false AttackL1:Stop() IdleL1:Play() CanAttack = true script.Parent.CanDamage.Value = true end end)
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
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()
-- This is assuming your Script is inside a Tool object. local humanoid = script.Parent.Humanoid local CanAttack = true -- Load the animations to be used later local AttackL1 = humanoid:LoadAnimation(script.AttackAnimationSwordL1) local IdleL1 = humanoid:LoadAnimation(script.IdleL1) script.Parent.Equipped:Connect(function() IdleL1:Play() end) script.Parent.Activated:Connect(function() if CanAttack == true then AttackL1:Play() IdleL1:Stop() wait(1) CanAttack = false AttackL1:Stop() IdleL1:Play() CanAttack = true script.Parent.CanDamage.Value = true end end)
If this solves your problem, make sure to accept the answer!