Get positon of a text cursor

thats not what i need though. thanks

	print(game.Players.LocalPlayer:GetMouse().X, game.Players.LocalPlayer:GetMouse().Y)

But you can get the mouse’s position whilst its in the typing blinking thing like this.

Btw sorry for unclean code I was typing it out.

that is not the text cursor and by text cursor i mean the blinker you see while you are typing

Ohhhh, yeah that’s weird. Oh well.

Could you elaborate on what you mean by moving the text cursor? Would it also be possible for me to take a glimpse at your code?

May I ask what you need this for though?

i dont have code to do that right now but i did think of a solution where i use textservice to put custom text aka string.sub(1, textbox.cursorposition) and some stuff

just making a frame follow the text cursor or the blinker

local function Update()
local textbounds = ts:GetTextSize(string.sub(textbox.Text,1, textbox.CursorPosition), textbox.TextSize, textbox.Font, textbox.AbsoluteSize)
local ScaleX = (textbox.TextBounds.X / textbox.AbsoluteSize.X)
local ScaleY = (textbox.TextBounds.Y / textbox.AbsoluteSize.Y)
textbox.Frame.Position = UDim2.fromOffset(textbounds.X , textbounds.Y)

heres my code currently yet its very buggy when i try to make another line (it only works good with 1 line) the textbox uses multiline btw. thanks again

In short, they are looking to made a custom text cursor using a frame that always stick to the textbox cursor position.

The textbox cursor is not always next to the text while you’re typing, the cursor can also move by clicking somewhere on the text, or using keyboard arrows.

good news! i made it what i need by doing this

function trimBeforeLastNewline(input)
	local lastNewlineIndex = input:match(".*()\n")
	if lastNewlineIndex then
		return input:sub(lastNewlineIndex + 1)
		return input

local function Update()
	local trimtext = string.sub(textbox.Text,1, textbox.CursorPosition-1)
	local textboundsY = ts:GetTextSize(trimtext, textbox.TextSize, textbox.Font, textbox.AbsoluteSize)
	local lastline = trimBeforeLastNewline(trimtext)
	local textboundsX = ts:GetTextSize(lastline, textbox.TextSize, textbox.Font, textbox.AbsoluteSize)
	textbox.Frame.Position = UDim2.fromOffset(textboundsX.X , textboundsY.Y)

thanks for everyone who helped!

1 Like