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

Equip Animation On My Gun Glitching Out Idle Animation?

Asked by 4 years ago

When the animations load into the gun an equip animation plays with a couple remote events. If you either spam between the gun and another item or unequip the gun before the equip animation and it's remote events are done the Idle animation doesn't go away.

function OnEquipped(mouse)
    script.Parent.Handle.DrawSound:Play()
    local EquipR = Tool:WaitForChild("EquipR")
    RecoilAnim = WaitForChild(Tool, "Recoil")
    IdleAnim = WaitForChild(Tool, "Idle")
    EquipAnim = WaitForChild(Tool, "Equip")

    ReloadAnim = WaitForChild(Tool, "Reload")
    FireSound  = WaitForChild(Handle, 'FireSound')
    MyCharacter = Tool.Parent
    MyPlayer = game:GetService('Players'):GetPlayerFromCharacter(MyCharacter)
    MyHumanoid = MyCharacter:FindFirstChild('Humanoid')
    MyTorso = MyCharacter:FindFirstChild('Torso')
    MyMouse = mouse
    if IdleAnim then
        if MyHumanoid ~= nil then
            local spamcheck = false
            if spamcheck == false then 
        IdleTrack = MyHumanoid:LoadAnimation(IdleAnim)
        wait(0.1)
        spamcheck = true
            elseif spamcheck == true then

        end
        end
    end
    if RecoilAnim then
    RecoilTrack = MyHumanoid:LoadAnimation(RecoilAnim)
  end
    if ReloadAnim then
    ReloadTrack = MyHumanoid:LoadAnimation(ReloadAnim)
    end


    WeaponGui = WaitForChild(Tool, 'WeaponHud'):Clone()
    if WeaponGui and MyPlayer then
        WeaponGui.Parent = MyPlayer.PlayerGui
        UpdateAmmo(AmmoInClip)
    end
    if EquipAnim then
    EquipTrack = MyHumanoid:LoadAnimation(EquipAnim)
    EquipTrack:Play()
    wait(1)
    EquipR:FireServer()
    Receiver:FireServer("PlaySound", "EquipSound")
    wait(0.6)
    if IdleAnim ~= nil then
    if IdleTrack ~= nil then
    IdleTrack:Play()
else if IdleAnim == nil then
    IdleAnim:Stop()
    IdleTrack:Destroy()
    IdleTrack:Stop()
end
end
end
end
    if MyMouse then
        MyMouse.Icon = "rbxassetid://18662154"
        MyMouse.Button1Down:connect(OnMouseDown)
        MyMouse.Button1Up:connect(OnMouseUp)
        MyMouse.KeyDown:connect(OnKeyDown)
        wait(0.25)
        StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, true)
        Check = true
    end
    end


function OnUnequipped()
    Check = false
    LeftButtonDown = false
    Reloading = false
    MyCharacter = nil
    MyHumanoid = nil
    MyTorso = nil
    MyPlayer = nil
    MyMouse = nil
    if EquipAnim ~= nil then
        IdleTrack:Stop()
    end
    if IdleAnim ~= nil then
    IdleTrack:Destroy()
    IdleTrack:Stop()
  end
    if EquipAnim then
        EquipTrack:Stop()
    end
  if RecoilTrack then
    RecoilTrack:Stop()
  end
  MyHumanoid = nil
  MyTorso = nil
  MyPlayer = nil
  MyMouse = nil
  if OnFireConnection then
    OnFireConnection:disconnect()
  end
  if OnReloadConnection then
    OnReloadConnection:disconnect()
  end
  if FlashHolder then
    FlashHolder = nil
  end
  if WeaponGui then
    WeaponGui.Parent = nil
    WeaponGui = nil
  end
end
if Reload == true then
Reload = false
end 

Answer this question