When I try to textservice gettextboundsasync to compare width of string,
first few calls throws both
“attempt to yield across metamethod/C-call boundary”
and “cannot resume non-suspended coroutine”.
why?
function font:get(name)
if registered[name] then
local fontApi = {}
function fontApi:apply(ui, weight, italic)
weight = weight or Enum.FontWeight.Regular
ui.FontFace = Font.new(registered[name], weight, italic and Enum.FontStyle.Italic or Enum.FontStyle.Normal)
end
function fontApi:width(text, size, rt, weight, italic)
local getText = Instance.new("GetTextBoundsParams")
getText.Text = text
getText.Font = Font.new(registered[name], weight or Enum.FontWeight.Regular, italic and Enum.FontStyle.Italic or Enum.FontStyle.Normal)
getText.Size = size
getText.RichText = rt or false
local result
result = textService:GetTextBoundsAsync(getText)
return result.X
end
return fontApi
end
end