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 4 years ago

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
0
hi, may i know which line does the error belong to? guest_20I8 266 — 4y
0
it is different every time but its the lines where I wrote Value:Play() applebugr21 30 — 4y
0
Is there any error for AttackL1:Play() ? Because i think the error is with IdleL1:Play(). guest_20I8 266 — 4y
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 — 4y

1 answer

Log in to vote
0
Answered by
megukoo 877 Moderation Voter
4 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()

-- 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!

Ad

Answer this question