so what im trying to do is as text is entered into the text label (text label parent is BillboardGUI) i would want the size to adjust to the text length/size (x axis)
any help would be appreciated
so what im trying to do is as text is entered into the text label (text label parent is BillboardGUI) i would want the size to adjust to the text length/size (x axis)
any help would be appreciated
You’re gonna need to provide more info like how they’re entering the text. Is it via a TextBox?
already tried that but since im using a billboard gui it doesnt have that property
oh okay but how are you accepting text input
so its a chat command you would say “/me” and put whatever at the end and it would show on the textlabel
oh that’s uh kinda simple
So you’d obviously set the text in the textlabel right. And then you’d get the scale for both X and Y dimensions of the text label
then you’d set it like so
local BillboardGui = your.gui
local TextLabel = your.label
-- set the text
BillboardGui.Size = UDim2.new(TextLabel.X.Scale, 0, TextLabel.Y.Scale, 0)
I’m not gonna write the whole thing out since I’m sure you’ve got something already written. This is just a layout for you
yes but is there anyway so if text is entered, the text label would get longer (x axis)?
It should. Give it a try I guess
u just wrote a code that reads the textlabel size not the actual string length if u know what i mean
Wait that wouldn’t be accurate? I dont think it would work if you used the character length unless you did some formula
im looking for somthing like this just in a billboard gui
I guess you could use TextService:GetTextBounds()
when the text is updated and you could update the X dimension of the Billboard accordingly if I understood you right
could you write a simple ccode so i can understand abit better?
also TextService:GetTextBounds() returns as a vector2 not udim
Yeah but it’s easy to convert
UDim2.new(Vector.X, 0, Vector.Y, 0)
sorry to be a pain but could u write a code example?
Yeah sure
local TextService = game:GetService("TextService")
local BillboardGui = path
local TextLabel = path
-- player added event above
Player.Chatted:Connect(function(msg)
if msg == "/me" then
local Text = string.sub(msg, 4, msg.length)
local Bounds = TextService:GetTextBounds(Text)
TextBox.Text = Text
TextBox.Size = UDim2.new(Bounds.X, 0, Bounds.Y, 0)
end
end)
something like that. You can also use math.clamp
to make sure the TextLabel size doesn’t go outside bounds
:GetTextBounds is not a command of the text service
My bad it’s actually TextService:GetTextBoundsAsync
And also that’s just some example code