Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

6 comments

0

string.char(0)? I dunno

0

it still returns the " "

0

Maybe you can use it as an reference

0

The NULL character is a literal whitespace. It expands string length.

0

oh thank you, maybe i can try string.byte

3 answers

✓ Accepted answer

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.

1 comment

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.

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...

1 comment

0

it couldn't work for me because i used :CaptureFocus() which caused this strange behavior, i fixed this year ago don't worry ;)

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

TextBox.Text = " "

2 comments

0

Nope, same result, thanks

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.