Contnt.Changed:connect(function(prop) if prop == 'Text' then local oldSize = Contnt.Size Contnt.Size = UDim2.new(1,0,0,999) local newSize=Contnt.TextBounds.Y Contnt.Size=oldSize Contnt:TweenSizeAndPosition( UDim2.new(1,0,0,newSize), UDim2.new(0,0,.5,-(newSize/2)), Enum.EasingDirection.Out,Enum.EasingStyle.Quad,1,true) end end)
So I am making a console (kind of a command bar for admin scripts), that I want to have expand when a user types that would then cause a new line to form. I am having the TextBox indicate that it is being changed in some form, if that change is Text, then the if then statement should run.
Problem is, this has been causing me to noticeably lag when I have to get out of Roblox Player. What I want the script to do is get the old size, that way it can tween more appealingly. Then when it gets that old size, expand the textbox long enough to get a new size to fit the TextBounds, and go back to the old size. I then want the script to Tween from the Old size to the new size.
I have tried various ways to keep the script from lagging me and to get it to work properly, yet am running out of options. Anyone got any ideas?
Thank you in advanced.
One of your problems here is that TextBounds.Y will never change unless the text size is changed or it has enough space to created another line when the multi-line property is set to true. If a new line can not be created, the text will continue to expand outside of the TextBox.
However, we can use a repeat loop to expand the TextBox until the multi-line texts fits inside of it. If you want it to tween to this new position, you can return it to it's original size and tween it to the new height.
Contnt.Changed:connect(function(property) if property == "TextBounds" then if not Contnt.TextFits then local initialSize = Contnt.Size local YOffset = 0 repeat Contnt.Size = Contnt.Size + UDim2.new(0, 0, 0, 1) YOffset = YOffset + 1 until Contnt.TextFits Contnt.Size = initialSize Contnt:TweenSizeAndPosition(Contnt.Size + UDim2.new(0, 0, 0, YOffset), Contnt.Position + UDim2.new(0, 0, 0, -YOffset/2), Enum.EasingDirection.Out,Enum.EasingStyle.Quad,1,true) end end end)