Also, even if you fixed the other issues, your function will never return any information about any unit other than "player" or "target" because of this (fixed formatting for readability):
Code:
if not UnitExists(unit) then
unit = "player"
else
unit = "target"
end
No matter what unit you pass to the function, it will overwrite it with "player" or "target".