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

Why is this sword animation not working in starterPlayer?

Asked by 6 years ago
Edited 6 years ago
local CanAttack = true
script.Parent.Equipped:connect(function()
    local idle = script.Parent.Parent.Humanoid:LoadAnimation(script.Idle)
    local attack = script.Parent.Parent.Humanoid:LoadAnimation(script.Attack)

    idle:Play()
end)

script.Parent.Activated:connect(function()
    local idle = script.Parent.Parent.Humanoid:LoadAnimation(script.Idle)
    local attack = script.Parent.Parent.Humanoid:LoadAnimation(script.Attack)

    if CanAttack == true then
        attack:Play()
        idle:Stop()
        wait(1)
        attack:Stop()
        idle:Play()
        CanAttack = true
        script.Parent.CanDamage.Value = true
    end
end)

1 answer

Log in to vote
0
Answered by 6 years ago

It's most likely because every time you make a new animation, never stopping the original. Try doing something like this:

local CanAttack = true
local i = script:WaitForChild("Idle)
local a = script:WaitForChild("Attack")
local hum = script.Parent.Parent:WaitForChild("Humanoid")
i.Parent = hum
a.Parent = hum
local idle = hum:LoadAnimation(i)
local attack = hum:LoadAnimation(a)
script.Parent.Equipped:connect(function()
    idle:Play()
end)
script.Parent.Activated:connect(function()
if CanAttack == true then
    attack:Play()
    idle:Stop()
    wait(1)
    attack:Stop()
    idle:Play()
    CanAttack = true
    script.Parent.CanDamage.Value = true
    end
end)

Also, another thing to note is that animations MUST be parented to the humanoid to work. This should fix all your problems.

Hope I could help. Have a nice day. -REALTimothy0812

0
it did not work DarkModule 34 — 6y
Ad

Answer this question