i want to get the position of the text cursor but i didnt find much tutorials on doing it and i just dont know what to do (i mean the actual absolute position like a udim2 or vector2 rather than a position in the string) . any help is appreciated
Could you elaborate a little further on what you mean by “position as in the string”? I’m not exactly sure what you mean by that and why you wouldn’t want the absolute position of what I’m assuming you mean the mouse is.
i meant the opposite. i do want the absolute position sorry for that
Ah, in that case whenever you grab the player’s mouse it has two attributes that can give you the absolute position you want (mouse.X
and mouse.Y
).
After you grab the player’s mouse via player:GetMouse()
you can just call those positions to get your absolute position.
Mouse’s Aboslute Position = (mouse.X
, mouse.Y
)
i dont mean the mouse i meant the text cursor in textboxes. (its that blinking thing while you’re typing. i want to get the position of that thing)
There is a textbox property called CursorPosition
. Perhaps that is what you are looking for?
the problem with that is that it will give you the positon in the string (a single number) but not an actual position. but i dont know how i would convert that into an actual position
I see. I don’t think there is really a way to grab an absolute position of the Cursor itself unless you maybe did some type of math with the textbox’s TextBounds and AbsolutePosition
?
The CursorPosition
gives you the position relative to the text inside of the textbox. What would you need an AbsolutePosition
of this for, if I may ask?
i tried testing it but it only goes to the end of the text and not the text cursor’s position also sorry for the late reply
im really bad at math and i dont really know what im suppossed to do
putting a frame next to the text cursor’s positon
also sorry for the late reply
Referencing the topic @Crygen54 posted, this is essentially what you would have to do then, you just need to tinker and understand the math behind it.
It’ll depend on your text alignment, You essentially divide the TextBound X by the Absolute Size X of the TextBox in order to find your scale (position based on how much space has been filled up). The negative and divided by 2 is just to realign the frame for the purpose of the cursor being centered or to the right (let’s say we have ours to the left for ease).
local Scale = (textBox.TextBounds.X / textBox.AbsoluteSize.X)
Next comes the UDim2.fromScale()
which is important because you want the actual scale of the frame’s position relative to the textbox (make sure your frame is inside your textbox). Now since we have nothing typed into the textbox, our x position will be set to 0 so that it will reside in UDim2.new(0, 0, 0, 0)
textBox.Frame.Position = UDim2.fromScale(Scale + 0.01, 0)
If you want to have a slight offset, you can just add 0.01 (or whatever value you want for spacing) to the X coordinate of the UDim2 and it should be offset so you can see your cursor. Hope this helps! :>
thank you so much for this reply but it wont work with vertically and the bigger problem is that it doesnt follow the text cursor rather it stays at the end of the text… im very sorry and thank you for your help
If you’re doing it vertically, then instead of the X coordinate you will have to manipulate the Y coordinate (it’s essentially the same thing just with Y instead of X). You’re very welcome btw and no need to apologize! I’m glad I can help you out. :>
Also if you mean have the frame like on the side then you’ll have to change X to a fixed value, because it does follow the cursor but without changing the other coordinate, it will just lay on top of the text + cursor.
i added Y support but this are the problem. again thanks
I see, whenever you line break is when you need to change the Y value, not change it the full time. That’s my bad I didn’t fully understand what you wanted.
So basically you just manipulate the X coordinate whenever you type normally, and whenever you go to break a line, reset the X to where the cursor is and then manipulate the Y value. That should hopefully fix your issue.
I think people are overcomplicating this too much, you can just use mouse enter which returns the X and Y coordinate of the mouse’s position in pixels.
thats the mouse positon and not the text cursor. thankss
Whoops, other one:
this happens when moving the text cursor not even typing. thanks again