When you first use this code, the loop doesn't do anything because the table is empty. There's nothing to loop through, so that if statement never happens.
Instead of a loop, use a ternary statement:
Lua Code:
if emotetype == "BONK" then
--print("Success")
bonktrack[btname] = bonktrack[btname] and bonktrack[btname]+1 or 1
print("BONKed " .. btname .. " " .. bonktrack[btname] .. " times")
else
print("BONK fail")
end
The line after the commented print is called a ternary statement or operator. I have also seen "logic shorthand". When Lua parses this, which is
variable = logic statement, it skips the rest of it when it reaches something true and returns the value of the last part of the true statement, whether it's true itself (the boolean value) or a non-false/non-nil value (result of math, another variable, the return from a function, etc). In this case, if there's a value at bonktrack[btname], it returns that value+1 into that key. If that key is nil, it skips the +1 and just sets it at 1.