TextFits does not update when a TextBox's Parent is hidden

This bug was experienced by many players on my PC exclusive game. The game’s chat GUI sizes messages by setting the Text of a message box and increasing its size until TextFits == true.

However, this was always hitting my iteration failsafe and leaving the message box massive as TextFits was never being set to true, even on very small messages.

I’m not sure if this change was intentional, but this code was working until recently.

To reproduce:

  • Place the following code in a LocalScript inside a PlayerGUI for a reproduction.
    local textBoxHolder = Instance.new("Frame", script.Parent)
    textBoxHolder.Visible = false

    local textBox = Instance.new("TextBox", textBoxHolder)
    textBox.Size = UDim2.new(0,10,0,20)

    -- The text box's width is way too small to fit its contents
    textBox.Text = "OnlyTwentyCharacters"
    print(textBox.TextFits) -- false, as expected

    -- This width should absolutely fit our text
    textBox.Size = UDim2.new(0,400,0,20)
    print(textBox.TextFits) -- false
    -- But it doesn't...

    -- Until we make the TextBox's parent visible
    textBoxHolder.Visible = true
    print(textBox.TextFits) -- true

This is likely due to performance optimization. Maybe when querying TextFits it can check if it has calculated or not that frame and do the calculations if appropriate.

2 Likes