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

Changing chat bar according to text length?

Asked by 7 years ago

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!

0
Or it scrolls while typing? NewVoids 97 — 7y

1 answer

Log in to vote
1
Answered by 7 years ago

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)

0
Looks good, but what if you backspace, NewVoids 97 — 7y
0
Ah.. Gimme a sec I'll see what I can conjure up. :D TinyPanda273 110 — 7y
0
That should work.. Not saying 100% but fairly close. TinyPanda273 110 — 7y
0
Thank you very much :) NewVoids 97 — 7y
View all comments (3 more)
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. TinyPanda273 110 — 7y
0
Also, what does the spawn function do? I looked at it on the wiki and never fully understood what it was. NewVoids 97 — 7y
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. TinyPanda273 110 — 7y
Ad

Answer this question