Getting TextBox CursorPosition Vector2 not returning the right position

Hi, I’m working on a autocomplete system where a autocomplete frame with a list of buttons will follow the TextBox’s cursor position within an x and y. The issue is, is that the function I used, returns the cursor position, however it is offsetted by 1 or more characters. I’ve attached the video below and the function below too.

local function GetCursorPosition(TextBox)
    local Text = TextBox.Text
    local CursorPosition = TextBox.CursorPosition
    local Font = TextBox.Font
    local FontSize = TextBox.TextSize
    local CursorBounds = TextService:GetTextSize(string.sub(Text, 1, CursorPosition), FontSize, Font, Vector2.new(math.huge, math.huge))
    local CursorX = CursorBounds.X
    local CursorY = CursorBounds.Y
    local CursorPosition = Vector2.new(CursorX, CursorY)
    return CursorPosition
end