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

How do you make a TextBox input be a variable?

Asked by 5 years ago
Edited 5 years ago

I would love to make a variable that changes to the input of a TextBox. I don't want it to be like this:

local input = TextBox.Text

That means that the variable equals to "TextBox.Text". I want it to be equaled to whatever the user has typed in. For example, if the user has typed in "Noob", then the variable would be "Noob", and not "TextBox.Text".

EDIT: If you don't get it, this is what I mean.

For example, if a user has typed in something into the TextBox, for example, "Cool", it could be used in directories. Currently, the variable "Input" is equal to "TextBox.Text". If you do this:

local input = TextBox.Text
game.Workspace.input.Humanoid.WalkSpeed = 10

It would be the same thing as saying:

game.Workspace.TextBox.Text.Humanoid.WalkSpeed = 10

And if the user has typed in "Cool", then it should be the same as saying

game.Workspace.Cool.Humanoid.WalkSpeed = 10

Hopefully that cleared things up a bit.

4 answers

Log in to vote
0
Answered by 5 years ago

You're doing it right, actually.

The one thing you may be missing is to update that variable whenever the user enters new text: Use events!

--....
local input=TextBox.Text
TextBox.FocusLost:Connect(function()
    input=TextBox.Text --Note: don't declare it as a local in here, or it'll be stuck.
    --Do stuff.
end)
--....
0
Check my edit! Dan_PanMan 227 — 5y
0
Did: Still got the same conclusion, you need to use an event and then do whatever you want with it. Your variable is whatever is [inside] the TextBox at that moment, not "Textbox.Text"! Jahaziel_VanDerHas 238 — 5y
Ad
Log in to vote
0
Answered by
Farsalis 369 Moderation Voter
5 years ago
Edited 5 years ago

What your asking is very confusing. When we declare a variable, it is declared at run-time..such as lua compiler. So if you text in the text box was "Hello" at run time, then the variable would be hello, But, it would stay that way, because there is nothing resonantly assigning that value. Its easier to show in code.

--Example 1--
--Lua Code Runs--
--TextBox.Text Is "Hello" aka.(The Original Text Of The TextBox.)--
--We Declare The Variable--
local var = TextBox.Text -- Curently This Is Equal To "Hello", since at runtime the player hasn't typed in anything else.

--Example 2--
--Lua Code Runs--
--TextBox.Text Is "Hello" aka.(The Original Text Of The TextBox.)--
--We Hook Into An Event--
TextBox.FocusLost:Connect(function()
    local var = TextBox.Text -- Currently This Is Whatever The User Types, since we are constantly updating it.
end)

Hope This Helped!

If this didn't help then go here: https://scriptinghelpers.org/guides/lua-quick-start-guide

0
Check my edit! Dan_PanMan 227 — 5y
Log in to vote
0
Answered by
sngnn 274 Moderation Voter
5 years ago
Edited 5 years ago

Try using:

local input = tostring(TextBox.Text)

What this does is convert the text inside the TextBox to a string, even if it contains numbers.

Log in to vote
0
Answered by 5 years ago

I have answered the question.

local input = script.Parent.Text
game.Workspace[input].Humanoid.Walkspeed = input

Workspace[input] is only used when the variable you want to go to is a string. For example, you could do Workspace[Scripting Helpers].whatever . You can remember it by saying [string here].

Answer this question