Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Changing chat bar according to text length?

I'm making a chat gui, and I'd like to be able to have a small chat bar, however if you type more than the chatbar's length, it gets bigger according to text length. This would work pretty much like the apocalypse rising chat.

How would I do this?

Thank you!

1 comment

0

Or it scrolls while typing?

1 answer

✓ Accepted answer

http://wiki.roblox.com/index.php?title=API:Class/TextBox

TextBox has a property that checks if your text fits. So based on this you can do something along these lines.

(Note: Written away from studio, not guaranteed to work 100%)

local box = script.Parent
local lastSize = 0
local boxMin = 75

spawn(function()
    while wait(0.01) do
        if box:IsFocused() then 
            if not box.TextFits then box.Size = box.Size + UDim2.new(0,8,0,0) end
            if string.len(box.Text) < lastSize then if box.Size.X.Offset > boxMin then box.Size = box.Size - UDim2.new(0,6,0,0) end end
        end
        lastSize = string.len(box.Text)
    end
end)

7 comments

0

Looks good, but what if you backspace,

0

Ah.. Gimme a sec I'll see what I can conjure up. :D

0

That should work.. Not saying 100% but fairly close.

0

Thank you very much :)

0

I played with it in studio. This is much more accurate. :D And accounts for your box being too small. :D and you're welcome.

0

Also, what does the spawn function do? I looked at it on the wiki and never fully understood what it was.

0

It creates the function without pausing the rest of the script. So it's like hey start this, so I can continue doing that. :D Here it's not really needed.

This discussion is preserved as it was. New answers, comments, and votes are closed.