Unable to cast Font to token on TextService:GetTextSize function

  1. What do you want to achieve?
    I want to use a custom font, specifically the “Silkscreen” font for a script that animates text (makes it shake or wiggle and stuff), so I use TextService:GetTextSize for it. but I get error

  2. What is the issue?
    I get an error “Unable to cast Font to token” whenever I try to call GetTextSize()

  3. What solutions have you tried so far?
    I tried getting help in different communities, I tried using values and attributes, even cloning a label with the font already on it, but nothing worked.

Problematic piece of code:


local text = "Hello world!"
local font = Font.new("rbxassetid://12187371840")
local fontSize = 30
local textSize = game.TextService:GetTextSize(text, fontSize, font, script.Parent.Frame.AbsoluteSize)

Any help would be appreciated, thank you!

You have to write the name of the font e.g “SourceSans”.

To do it by the asset id you need GetTextBoundsAsync()

Even then I think for the asset id that uses I think it’s written like “rbxasset://fonts/families/GrenzeGotisch.json” instead of numbers.

Take a look at this

Alright, using GetTextBoundsAsync() did fix the initial error, but now whenever I give the TextLabel the font it seems to be unable to use :thinking:

Nevermind, using FontFace instead of Font fixed it.
Thanks for the help!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.