How to scale a ScrollingFrame's X CanvasSize, based on the length of text

Hey! I’m trying to scale a ScrollingFrame’s CanvasSize accordingly to the size of a TextBox’s Text.


As you can see in the video^ , the canvas’s Y size scales accordingly, but the X does not.
I tried using TextService:GetTextSize() but it doesn’t seem to work.

local editorModule = require(script.Parent.Parent:WaitForChild('EditorModule'))
local input: TextBox = script.Parent:WaitForChild('input')
local lineCounter = script.Parent:WaitForChild('lineCounter')
local scrollingFrame = script.Parent

local defaultLineText = lineCounter:WaitForChild('number'):Clone()
defaultLineText.Parent = script
defaultLineText.Visible = false

local UIS = game:GetService('UserInputService')
local textService = game:GetService('TextService')

input:GetPropertyChangedSignal('Text'):Connect(function()
	local line_count = (editorModule.get_textbox_length(input) + 1)
	editorModule.set_lines(lineCounter, defaultLineText, line_count, input)
	local size = textService:GetTextSize(input.Text, input.TextSize, input.Font, Vector2.new(input.AbsoluteSize.X, 0))
	scrollingFrame.CanvasSize = UDim2.new(0, size.X, 0, 15 * line_count)
	editorModule.set_canvas_y_position_max(scrollingFrame)
end)

input.Focused:Connect(function()
	local line_count = (editorModule.get_textbox_length(input) + 1)
	editorModule.set_lines(lineCounter, defaultLineText, line_count, input)
end)

UIS.InputBegan:Connect(function(key)
	if key.KeyCode == Enum.KeyCode.Return then
		if UIS:GetFocusedTextBox() ~= nil and UIS:GetFocusedTextBox() == input then --// They entered a new line.
			editorModule.on_enter(lineCounter)
		end
	end
end)

Help would be very much appreciated! :slight_smile:

You could try to put a horizontal scrolling frame inside of the vertical scrolling frame.

The scrolling frame is able to scroll in both directions X & Y