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

Why will my swing animation not play?

Asked by
Txeer 46
4 years ago

I am currently scripting a sword. I am trying to make it play a swing animation when it is used. It won't play the animation.

local canHurt = true



    script.Parent.Activated:Connect(function()

        if canHurt == true then

        canHurt = false

        local hum = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")

        local swing = hum:LoadAnimation(script.Parent.Swing)

        swing:Play()

        wait(1)

        canHurt = true

        end
    end)
0
any output erros? AntoninFearless 622 — 4y
0
None Txeer 46 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

Ok so I tried this out and so far it worked. Assuming you have a localscript directly under the tool, put in the following:

local db = false --To prevent spamming the animation
script.Parent.Equipped:connect(function()
    script.Parent.Activated:connect(function()
        if db == false then
            db = true
            local player = game:GetService('Players').LocalPlayer --We get the player
            local hum = player.Character:WaitForChild('Humanoid') --We get the humanoid
            local anim = script.Parent.Animation --This is the animation which is also directly under the tool
            hum:LoadAnimation(anim):Play() --Plays the animation
            wait(1) --Wait time before allowing player to use the animation again
            db = false --Allows the player to use the animation
        end
    end)
end)

This worked out and played the animation, however, the arm the player is holding the tool with won't animate. I don't know how to fix that issue but I hope that this will help you out a lot more in the future.

Ad

Answer this question