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

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

Asked by 5 years ago

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?

1
The username variable will not update if the text is changed. And these two statements are only going to execute once. User#24403 69 — 5y
0
And how can I make it change? Sonnenroboter 336 — 5y

3 answers

Log in to vote
0
Answered by
174gb 290 Moderation Voter
5 years ago

Please provide explanation with your answers. Simply posting code does not spread knowledge of integral scripting processes which helps people understand the logic and reasoning behind your answer.
local username = script.Parent.UserName

username.Changed:connect(function()
   print(username.Text)
end)
0
It works, but only in Localscrpts. That's bad because I can't make Http requests with them. Sonnenroboter 336 — 5y
0
Well you need to add a remote function/event then. SomeDumbNinja -2 — 5y
Ad
Log in to vote
0
Answered by
VicyX 27
5 years ago

To make it change whenever the text changes do:

local Username

script.Parent.UserName.Changed:Connect(function()
    Username = script.Parent.UserName.Text
end)
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago
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.

0
Text isn't the Text. It's the bool enterpressed. https://developer.roblox.com/api-reference/event/TextBox/FocusLost Sonnenroboter 336 — 5y
0
My bad, I fixed it SomeDumbNinja -2 — 5y

Answer this question