Lua Code:
thisButton = "ButtonFrame" .. k
-- at this point thisButton is a string, not an actual button.
thisButton:ClearAllPoints()
-- so this will fail
You need to resolve the string to an actual button either stored in a local or the global table.
Wiithout know what ButtonTable holds my guess is you could use v instead of all the "thisButton" references.