1.  function bankGems()
          local itemCount = 39996
          while itemCount < 40107 do
               for bag = 5, 11 do
                    for slot = 1, GetContainerNumSlots(bag) do
                         local itemLink = GetContainerItemLink(bag, slot)
                         local name,_,_,_,_ = GetContainerItemInfo(bag, slot)
                         local extract = gsub(itemLink, "\124", "")
                         if name and string.find(extract, itemCount) then
                              UseContainerItem(bag, slot)
                              itemCount = itemCount + 1
                         end
                    end
               end
               itemCount = itemCount + 1
          end
     end
    

    What Im trying to do is basically when I have my bank opened, I use the script and it'll find each gem (located by using the itemID, itemCount variable) and moves it into my bags. It works the first time I press it, but when I press it again, it won't do anything. The problem I found out was that if there's no gem at the slot before an occupied gem slot, the script seems to just stop working. Sort of like this:

    [5,1] [5,2] [5,3] [5,4]

    1st slot has a gem, 2nd slot does not, 3rd slot has gem, 4th slot has gem. The script only moves the gem in slot 1, but then stops. But if I fill the 1st and 2nd slot with a gem, it starts working again and therefore moves all 4 gems. Im completely stumped.

    You don't have a check for itemLink being nil, so you should be getting an error. You should first enable that you have "Display Lua Errors" enabled under Interface Options -> Help.