--!strict local TextService = game:GetService("TextService") local Constants = require(script.Parent.Constants) local Sizing = {} local function FitsHeight(Text: string, Size: number, Face: Font, Height: number): boolean local Params = Instance.new("GetTextBoundsParams") Params.Text = Text Params.Size = Size Params.Font = Face Params.Width = math.huge local Ok, Bounds = pcall(function() return TextService:GetTextBoundsAsync(Params) end) if not Ok then return Size <= Height end return Bounds.Y <= Height end function Sizing.Resolve(Text: string, Face: Font, Box: Vector2): number local Height = Box.Y if Height <= 0 then return Constants.MaxTextSize end local Best = Constants.MinTextSize local Low = Constants.MinTextSize local High = math.min(Constants.MaxTextSize, math.floor(Height + 0.5)) while Low <= High do local Mid = math.floor((Low + High) / 2) if FitsHeight(Text, Mid, Face, Height) then Best = Mid Low = Mid + 1 else High = Mid - 1 end end return Best end return Sizing