Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Trying To Expand TextBox When Someone Types, Getting Lag, Anyone Have Any Options?

Asked by
M39a9am3R 3210 Moderation Voter Community Moderator
8 years ago
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.

0
1st this should be a localscript (just checking) 2nd you could reduce the transition time from 1 to somthing like 0.02 Hope this helps User#5423 17 — 8y
0
@kingdom5, yeah, no it definitely does not... M39a9am3R 3210 — 8y

1 answer

Log in to vote
0
Answered by
BlackJPI 2658 Snack Break Moderation Voter Community Moderator
8 years ago

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)
0
I tested it, it does not seem to want to go into the if then statement. M39a9am3R 3210 — 8y
0
I removed the size comparison, not sure why I had it in there. Try it now! BlackJPI 2658 — 8y
Ad

Answer this question