Hello, I am currently scripting a police Radio. I have come to a point, where I want to size the TextLabel automatically from the content. Any ideas? Thanks, Alex
You could use TextService
TextService has a function called :GetTextSize() and it returns a Vector2 which contains an X and Y to scale your TextLabel. Make sure your TextLabel is Scaled.
local TS = game:GetService("TextService") local message = script.Parent local frame = script.Parent.Parent local fontSize = Enum.FontSize.Size18 local font = Enum.Font.SourceSansLight local newSize = TS:GetTextSize(message.Text,fontSize,font,frame.AbsoluteSize) message.Size = UDim2.new(0,newSize.X,0,newSize.Y)
OR
You can just use TextBounds
Either or works!
Hope this helped!
In the properties of the textlabel scroll down to the text section(where you would do stuff like change what the text says or change the text color) and select the box that says "TextScaled." And done! Or in a script it would be for example:
local player = game.Players.LocalPlayer local pguiLabel = player.PlayerGui:WaitForChild("ScreenGui").Frame.TextLabel pguiLabel.TextScaled = true
Please accept this answer if it helped.