Consistent text font sizing solution (e.g. animated text, multiple text boxes, etc...)

I thought I’d post this solution as I couldn’t find any simple and clear answers on the forums.


Problem:
Using text-scaled will cause text sizes to change based on the amount of text inside the label. Here you can see the less text, the larger the font size.
image
image


Solution:
Scale the text manually based on the players viewport size, this is well known but I never saw someone actually post a simple script to do it.

  1. Turn off text scaling
  2. Choose the font size you want
  3. Place this script into a Local Script inside your text label
local descriptionLabel = script.Parent
local camera = workspace.CurrentCamera
local defaultViewportX = 1530 --The viewport size of your roblox editor
local defaultTextSize = descriptionLabel.TextSize
local m = defaultTextSize / defaultViewportX

local function UpdateText()
	local viewportSizeX = workspace.CurrentCamera.ViewportSize.X
	descriptionLabel.TextSize = m * viewportSizeX
end

camera:GetPropertyChangedSignal("ViewportSize"):Connect(UpdateText)
UpdateText()
  1. Replace “defaultViewportX” with your studios current x-axis viewport size, you can find out the viewport size by placing this in the console:
    print(workspace.CurrentCamera.ViewportSize.X)

Now no matter the person’s resolution/device, the text size will scale based on the viewport X size. Hope this helps.

*Edited to correct script mistake

3 Likes

In the case you’re just trying to animate text, this would probably be the better thing to look into which wouldn’t require having to manually calculate the text size:

I think this should be somewhere in #resources:community-tutorials