I've been struggeling with this issue when playing around with some unitframes and trying to add the functionality with clicking the unitframe to target myself. It just will not work.
It doesnt taint either, it just seems to do nothing when going trough the SetAttribute. If I add a print after the two SetAttribute, it does indeed print, but it does not target me, nor does it give an error. I can not get it to work when trying the macrotext method either.
local uframe = CreateFrame("Button", "uframe", UIParent,"SecureUnitButtonTemplate")
I figured it out. I moved the 'buttoncheck' from the SetScript checking for buttons to an OnUpdate script (if script is the correct 'term'?) and it worked just like intended. Been messing on and off with this a few times, so very happy to finally get it to work.
Thanks for the tips guys, and Blazeflack was kinda right, hehe =)