Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
3

How to set TextBox's text to 'nil'?

Asked by
imKirda 4491 Moderation Voter Community Moderator
3 years ago
Edited 3 years ago

I am trying to remove text of TextBox, my problem is that of course you can't do

TextBox.Text = nil

I tried doing

TextBox.Text = ""

But this has one problem i am trying to fix, it's not making the text empty, it is adding some invisible character to it which results in PlaceholderText to not be visible because the text is not empty, there is that space, how would i remove it? I tried using string.sub, no result.

Thanks, kirda

0
string.char(0)? I dunno Block_manvn 395 — 3y
0
it still returns the " " imKirda 4491 — 3y
0
Maybe you can use it as an reference Block_manvn 395 — 3y
View all comments (2 more)
0
The NULL character is a literal whitespace. It expands string length. DeceptiveCaster 3761 — 3y
0
oh thank you, maybe i can try string.byte imKirda 4491 — 3y

3 answers

Log in to vote
2
Answered by 3 years ago
Edited 3 years ago

From what I've tried, this returns a length of 0:

local text = script.Parent.Text -- blank text
print(#string.char(string.byte(text))) -- 0

I'm assuming whatever character it's adding isn't shown but adds to the string length. Have you possibly considered printing the length of the string to see if that character is there? If the length is 1, there's a character being added. PlaceholderText only works if #text is 0.

0
oh thanks yeah actually there really is some invisible character. weird is that it does not count as a letter because i used :CaptureFocus but did not include it in the post so i'm simply dumb, sorry for that i feel bad now. imKirda 4491 — 3y
Ad
Log in to vote
1
Answered by 2 years ago

try just going into the textlabel properties and scroll down to "text:" then remove everything from it. don't put a space or anything, just leave it blank. it worked for me so i don't know why it couldn't work for you...

0
it couldn't work for me because i used :CaptureFocus() which caused this strange behavior, i fixed this year ago don't worry ;) imKirda 4491 — 2y
Log in to vote
0
Answered by 3 years ago

The only way I can think of making it appear blank is to use a space

TextBox.Text = " "
0
Nope, same result, thanks imKirda 4491 — 3y
0
You're adding a whitespace. The goal is to have zero space in the string. The whitespace will make the string length 1, when it should be 0. DeceptiveCaster 3761 — 3y

Answer this question