Resize Text scale without using TextScaled

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? I would like for the text to be the same on any type of device (bigger or smaller screens)
  2. What is the issue? If I used TextScaled it would ruin the text alot if it was 3 words they would appear super big and I didn’t want that
  3. What solutions have you tried so far? I looked up on dev forum and the scripts people used didn’t work, AI didn’t work aswell (dont bully me but it was my last resort)

PS5 screen (bigger):

My screen:

Explorer:


(BG is the base frame where everything is, Name is the “Theo” text, Port is the square you see on the left of Theo, and dialogue is the text label where the scaling should happen)

Also the base scale is 25

(The script i saw most use and try and also that AI sort of gave me):

local sizeOn1080 = 35  --base text size for 1080p res
local defaultWidth = 1920
local defaultHeight = 1080
local camera = workspace.CurrentCamera

local function updateTextSize()
	local viewport = camera.ViewportSize
	local scaleX = viewport.X / defaultWidth
	local scaleY = viewport.Y / defaultHeight
	local scaleFactor = math.min(scaleX, scaleY)
	local newSize = sizeOn1080 * scaleFactor
	script.Parent.UITextSizeConstraint.MaxTextSize = newSize
end

camera:GetPropertyChangedSignal("ViewportSize"):Connect(updateTextSize)
updateTextSize()

please don’t mind the text :sob:

Forgot to say but if someone knew a way to do that with the UIStroke aswell, would be lovely

Why not use TextSizeConstraints?

i tried and i dont really know how to use them well i was thinking more of an automated way??

What’s the resolution on the PS5 screen?

Is that in studio or in the player?

its in studio and by automatic i mean it adapts to the resolution you have

Just mod the script to work for uistrokes?

Basically what you should prob do is at the start grab all textlabels/uistrokes and create an attribute for their original sizes at 1920x1080. Then, you can just scale the original size according to scaleFactor every time viewport changes and on initialize. The script ai generated for you is almost there, but you just needa fix it up a bit to actually work properly and include uistrokes.

It won’t result in consistent text sizes and it would be better to use a script for text sizes. You can’t really determine a min/max text size for all devices. You can set the max to 15 for a pc user, but maybe that’s too big on a phone. Set the max to a large number, and you run into the same issue of inconsistent text sizes from textscaled (textsize alternates between large and small sizes depending on dialogue text length). I guess you could dynamically adjust uitextsizeconstraint min/max with a script, but you might as well just turn off textscaled and edit textsize directly at that point.

Thank you alot i think I get what you mean, so in roblox sudio i just get the resolution at which i did that text size, then take out a scalefactor like current res / original res and multiply the base text size to that factor? I think thats what you meant right?

yup scale factor like you had in the script:

for _, text in ... do

text:SetAttribute("OriginalSize") = text.TextSize

end

-- sm like this on setup
--... viewport variables yada yada
local scaleX = viewport.X / defaultWidth
local scaleY = viewport.Y / defaultHeight
local scaleFactor = math.min(scaleX, scaleY)

-- and then something like this
text.TextSize = text:GetAttribute("OriginalSize") * scaleFactor
stroke.Thickness = stroke:GetAttribute("OriginalSize") * scaleFactor
-- make this into a function and update it when necessary

of course, you might want to polish it up a bit, add a clamp to make text not become too small (or a setting for text size multiplier), etc.

1 Like

i have a question if i use the built in device emulator will the resolution change or no (so i can test)

yea it should and it tells you the resolution on the right of the device name.

are you using scale, not offset on the text? (I mean the actual text’s size)

yea yea every ui thing you see uses scale

ok ill try that out and let you know

could ya send a pic of like the textlabel selected on usual screens and then on ps5 screen?

like this?

ps5:

pc:

yeah I’m not sure, looks like a uitextsizeconstraint issue but idk

no no what im talking about is the accuall text now the textlabel size

I also asked an AI and it recommended a different approach. It suggested making the entire UI (or in this case, just that dialogue frame) use offset size and rewriting the scaling system to use UIScale. With this, you can set the text’s size to a fixed number and the script will adjust the frame’s UIScale which scales the UI, including the text. (feel free to bully me for asking AI :man_shrugging:)

-- Written by AI (Claude Sonnet 5)

local uiScale = script.Parent
assert(uiScale:IsA("UIScale"), "This script expects its Parent to be a UIScale instance")

local camera = workspace.CurrentCamera

-- Baseline resolution you designed the UI at
local BASELINE_X, BASELINE_Y = 1920, 1080 -- CHANGE THIS

local function updateScale()
	local viewport = camera.ViewportSize
	local scaleX = viewport.X / BASELINE_X
	local scaleY = viewport.Y / BASELINE_Y
	-- Use the smaller of the two so UI never overflows either axis
	local scale = math.min(scaleX, scaleY)

	-- Optional: clamp so it doesn't get absurdly tiny/huge on extreme aspect ratios
	-- scale = math.clamp(scale, 0.5, 1.5)

	uiScale.Scale = scale
end

camera:GetPropertyChangedSignal("ViewportSize"):Connect(updateScale)
updateScale()

Outcome: