local TextService = game:GetService("TextService")
local container = script.Parent -- should be a Frame or something like that
container.ClipsDescendants = true
local box = container.TextBox
local PADDING = 4 -- pixels to the left/right of text
local function Update()
local reveal = container.AbsoluteSize.X
if not box:IsFocused() or box.TextBounds.X <= reveal - 2 * PADDING then
-- we aren't focused, or we fit so be normal
box.Position = UDim2.new(0, PADDING, 0, 0)
else
-- we are focused and don't fit, so adjust position
local cursor = box.CursorPosition
if cursor ~= -1 then
-- calculate pixel width of text from start to cursor
local subtext = string.sub(box.Text, 1, cursor-1)
local width = TextService:GetTextSize(subtext, box.TextSize, box.Font, Vector2.new(math.huge, math.huge)).X
-- check if we're inside the box with the cursor
local currentCursorPos = box.Position.X.Offset + width
-- adjust if necessary
if currentCursorPos < PADDING then
box.Position = UDim2.fromOffset(PADDING-width, 0)
elseif currentCursorPos > reveal - PADDING - 1 then
box.Position = UDim2.fromOffset(reveal-width-PADDING-1, 0)
end
end
end
end
Update()
box:GetPropertyChangedSignal("Text"):Connect(Update)
box:GetPropertyChangedSignal("CursorPosition"):Connect(Update)
box.Focused:Connect(Update)
box.FocusLost:Connect(Update)
Hey! I don’t think you need a scrolling frame around the TextBox, and I think this is the source of your issue. See my example video below. I’ve attached the rbxmx of this TextBox onto my post.
When you have a scrolling frame around the text box, the text box can no longer automatically scroll itself. The text box’s scrolling is based on its own instance size, so when you let it grow to any size, it doesn’t handle text scrolling for you. If you really need a scrolling frame around it, you’ll need to manually track the position of the cursor using the current CursorPosition and GetTextSize. So basically you’d be recreating the scrolling that text box already does for you
Wow, I hadn’t thought about that. But when FocusLost, it takes me back to the beginning and when I want to go down, scrolling the mouse wheel doesn’t work. So, it works by pressing down on the arrow keys. This seems a bit difficult.