Custom Text Scaled Script


<advertisement voice>

The Smart Resize Script by Bear Development Team can resize TextLabels, TextButtons, and TextBox’s TextBoxs not recommended text size to automatically fit the screen, just like the property TextScaled. But the differences between TextScaled and SmartResize are 1) SmartResize changes the TextSize property too, so you can find the text size even when it’s scaled and 2) Smart Resize can resize multiple text object to the same size!

</advertisement voice> lol

Text Scaled:


Notice each of the text labels are different sizes, which looks weird

SmartResize:


Each one is the same size and fits, so it looks good (this isn’t a good example though)!

Setting Up

To set it up, put the local script inside of the GUI inside of Starter GUI. Then, open the script. You should see something like this:

--- CONFIGURATIONS ---
local GuiObjects = {script.Parent.TextLabel1, script.Parent.TextLabel2, script.Parent.TextLabel3}
local ResizeWithObject = true
local ResizeWithScreen = true
local ResizeWithText = true
local PrintResults = true
  • GuiObjects: A list of all the GuiObjects that will be affected by that script (they will all be the same size at the end)
  • ResizeWithObject: Whether the text should be resized every time the object is resized
  • ResizeWithScreen: Whether the text should be resized every time the screen is resized
  • ResizeWithText: Whether the text should be resized every time the text is changed
  • PrintResults: Whether the results (text size) should be printed into the console (good for testing)

Know Problems/Errors

The only issue I know of is it takes a minute to resize because it has to resize each object:


Don’t worry! This will probably be fixed sometime in the near future!

Edit: whoops forgot the open-sourced part of it:

Code
LocalScript
--- CONFIGURATIONS ---
local GuiObjects = {script.Parent.TextLabel1, script.Parent.TextLabel2, script.Parent.TextLabel3}
local ResizeWithObject = true
local ResizeWithScreen = true
local ResizeWithText = true
local PrintResults = true

--[==[
--- NOTE ---
The only allowed classes are:
 - TextLabel
 - TextButon
 - TextBox
]==]--

--- FUNCTIONS ---

-- No editing needed here, but it's open-sourced so you can look through it!
local debounce = false
local event = script.ResizeText
local TextSizes
local currentSize
local TextBoxSize
local TextSize

local OldTextSize

local smallest

function adjustSize()
	if debounce then return end
	debounce = true
	TextSizes = {}
	for _, object in pairs(GuiObjects) do
		object.TextSize = 1
		currentSize = 101
		TextBoxSize = object.AbsoluteSize
		object.TextScaled = false
		object.TextTruncate = Enum.TextTruncate.None
		repeat
			currentSize = currentSize - 1
			event:FireServer(object, currentSize)
			event.OnClientEvent:Wait()
			if object.TextFits then
				TextSizes[#TextSizes + 1] = currentSize
				currentSize = "DONE"
			end
			if currentSize ~= "DONE" then
				if currentSize < 1 then
					warn("A FATAL ERROR OCCURED! " .. tostring(currentSize))
					return
				end
			end
		until currentSize == "DONE"
	end
	
	smallest = TextSizes[1]
	for _, num in pairs(TextSizes) do
		if num < smallest then
			smallest = num
		end
	end
	
	for _, object in pairs(GuiObjects) do
		object.TextSize = smallest
	end

	if PrintResults then
		print("Changed " .. #GuiObjects .. " TextSize to " .. smallest)
	end

	debounce = false
end

adjustSize()

local camera = game.Workspace.CurrentCamera


for _, object in pairs(GuiObjects) do
	if ResizeWithObject then
		object:GetPropertyChangedSignal("AbsoluteSize"):Connect(adjustSize)
	end
	if ResizeWithText then
		object:GetPropertyChangedSignal("Text"):Connect(adjustSize)
	end
end


if ResizeWithScreen then
	camera:GetPropertyChangedSignal("ViewportSize"):Connect(adjustSize)
end

There is a remote event in between the local script and the server script named ‘ResizeText’

ServerScript
local event = script.Parent

function run(_, object, size)
	object.TextSize = size
	event:FireAllClients()
end

event.OnServerEvent:Connect(run)
15 Likes

I’ve removed the tags from the title–those can go into the “optional tags” section. :slight_smile:

1 Like

Looks cool! Hopefully I can find a way to use this in the future!

1 Like

FYI: ModuleScript is better than just script for this case, and rather than telling the user not to put classes other than textbox, textlabel, textbutton, please implement a class checker, to check whether it is either textbox, textlabel or textbutton

2 Likes

I will do this and fix the problem under Known Problem/Errors in the next update.
I will also look into module scripts because I know nothing about them lol. :smile: