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

TextBox.Text is always an empty string. How can I fix that?

Hello dear scriptinghelpers community. I am doing an login system but TextBox .Text always return an empty String:

local username = script.Parent.UserName.Text
print(username)

->
How can I fix that?

2 comments

1

The username variable will not update if the text is changed. And these two statements are only going to execute once.

0

And how can I make it change?

3 answers

✓ Accepted answer
local username = script.Parent.UserName

username.Changed:connect(function()
   print(username.Text)
end)

2 comments

0

It works, but only in Localscrpts. That's bad because I can't make Http requests with them.

0

Well you need to add a remote function/event then.

To make it change whenever the text changes do:

local Username

script.Parent.UserName.Changed:Connect(function()
	Username = script.Parent.UserName.Text
end)

function TextEnded()
    local username = script.Parent.UserName.Text -- Change the username variable into the text
    print(username) -- Prints the username
end
script.Parent.UserName.FocusLost:connect(TextEnded) -- This activates when the player stops interacting with the TextBox.

You can use the FocusLost function to change the username variable.

2 comments

0

Text isn't the Text. It's the bool enterpressed. https://developer.roblox.com/api-reference/event/TextBox/FocusLost

0

My bad, I fixed it

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