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

Why doesn't my animation play in online mode?

Asked by
yumtaste 476 Moderation Voter
9 years ago

I'm making some tools that rely on animations to work. However, the animations continue to break and not work in online mode. They may occasionally work in solo mode, but then they break, and I have to go into the animation object and cut the code, then paste it back in. It keeps working and then breaking like that and I'm sick of it! Please help! Everything is defined and stuff, just the animation continues to break.

Posted below is the code in case there are any scripting errors.

local animation = script:FindFirstChild("swingAxe")

local animTrack = nil

local canPlay = true

local swinging = script.Parent.swinging

function playSwingAnim()
    if canPlay then
        local player = game.Players.LocalPlayer.Character
        canPlay = false
        animTrack = player:FindFirstChild("Humanoid"):LoadAnimation(animation)
        swinging.Value = true
        animTrack.KeyframeReached:connect(function(keyframeName)
            if keyframeName == "End" then
                canPlay = true
                swinging.Value = false
            end
        end)
        animTrack:Play()
    end
end

script.Parent.Equipped:connect(function(m)
    m.Button1Down:connect(function()
        playSwingAnim()
    end)
end)

Answer this question