function playAnimation(r,f,a)local m=math.random(1,animTable[r].totalWeight)local g=m local j=1 while m>animTable[r][j].weight do m=m-animTable[r][j].weight j=j+1 end local n=animTable[r][j].anim if n~=currentAnimInstance then if currentAnimTrack~=nil then currentAnimTrack:Stop(f)currentAnimTrack:Destroy()end currentAnimSpeed=1.0 currentAnimTrack=a:LoadAnimation(n)currentAnimTrack:Play(f)currentAnim=r currentAnimInstance=n if currentAnimKeyframeHandler~=nil then currentAnimKeyframeHandler:disconnect()end currentAnimKeyframeHandler=currentAnimTrack.KeyframeReached:connect(keyFrameReachedFunc)end end

function playAnimation(animName, transitionTime, humanoid) 

    local roll = math.random(1, animTable[animName].totalWeight) 
    local origRoll = roll
    local idx = 1
    while (roll > animTable[animName][idx].weight) do
        roll = roll - animTable[animName][idx].weight
        idx = idx + 1
    end
    --print(animName .. " " .. idx .. " [" .. origRoll .. "]")
    local anim = animTable[animName][idx].anim
    -- switch animation
    if (anim ~= currentAnimInstance) then
        if (currentAnimTrack ~= nil) then
            currentAnimTrack:Stop(transitionTime)
            currentAnimTrack:Destroy()
        end
        currentAnimSpeed = 1.0
        -- load it to the humanoid; get AnimationTrack
        currentAnimTrack = humanoid:LoadAnimation(anim)
        -- play the animation
        currentAnimTrack:Play(transitionTime)
        currentAnim = animName
        currentAnimInstance = anim
        -- set up keyframe name triggers
        if (currentAnimKeyframeHandler ~= nil) then
            currentAnimKeyframeHandler:disconnect()
        end
        currentAnimKeyframeHandler = currentAnimTrack.KeyframeReached:connect(keyFrameReachedFunc)
    end
end