From the manual, there is an expression to get the size in pixels of the text.
Return the size of the actual text content within the text object's rectangle. Note the Text object must be drawn before these have the correct values. If you set the text then immediately access these expressions, they won't yet have the correct value. Adding a Wait 0.1 seconds action will usually solve this.
You would then set the size of the text object to this amount.
set text to "my text"
set text object width to expression get text width