Unsure of how to decrease chatbar size after content is removed from line

Hello! I’ve been searching around the ROBLOX DevForum however I was not capable of finding anything that is supportable to my type of coding, I’ve been trying for quite some time now and I still couldn’t figure out how to decrease the size.

I’ve tried many ways however I’m not capable of it, I’d appreciate if there is anyway to support this type of coding for a chatbar.

NOTE

I want it to keep the exact same coding, I don’t want to use it from the chat modules and etc, because they do not fit in the same code as I’m going for.

LOCAL SCRIPT

local Frame = script.Parent;

local ChatBoxBackground = Frame:WaitForChild("ChatBoxBackground");
local ChatBar = ChatBoxBackground:WaitForChild("MessageChatBox");

local XOffset = ChatBar.Size.X.Offset;
local YOffset = ChatBar.Size.Y.Offset;

ChatBar:GetPropertyChangedSignal("Text"):Connect(function()
	local TextFits = ChatBar.TextFits;
	local ContentText = ChatBar.ContentText;
	
	if(not TextFits) then
		Frame.Size = UDim2.new(0, Frame.Size.X.Offset, 0, ChatBar.TextBounds.Y) + UDim2.new(0, 0, 0, 37);
		ChatBoxBackground.Size = UDim2.new(0, ChatBoxBackground.Size.X.Offset, 0, ChatBar.TextBounds.Y) + UDim2.new(0, 0, 0, 31)
		ChatBar.Size = UDim2.new(0, XOffset, 0, ChatBar.TextBounds.Y) + UDim2.new(0, 0, 0, YOffset);
	end
end);

If there’s any way let me know, this is what I’m trying to achieve.

EXAMPLE

If you have anything that is related towards this and might help me let me know, I want it to stay as the same code as it is : )

UI


I’m quite new to this “textfit” and etc, so let me know of anything that may be a great source to helping!

I don’t see an issue; maybe the frame it’s only reverting a frame you can’t see? I would probably add an extra check and manually revert the size.

Sorry, I should’ve been more clear, it’s not that, It’s the fact I can’t get it to decrease it’s size after a content of a line of text is removed so like an example:

“Chat - 1st Line”
“ChatBar - 2nd Line”

Then when it’s cleared for the 2nd line
The frame should go back to it’s original size or decrease its size if its longer than 2 lines.

So it shouldn’t be leaving open the cleared lines that were removed.