I was using a TextBox as a player input device and once I click submit, it prints to the console. But, instead of printing what I want, it prints absolutely nothing. Below is a LocalScript within a ScreenGui.
local TextBox = script.Parent.TextBox
local inputText = TextButton.Text
script.Parent.SubmitButton.Activated:Connect(function()
print(inputText)
end)
Output:
20:00:40.423 -
(It literally prints out nothing.)
Is there something wrong with my script, if so please let me know, thanks.
local TextBox = script.Parent.TextBox
script.Parent.SubmitButton.Activated:Connect(function()
print(tostring(TextBox.Text))
end)
You set the variable for the Text box’s text before the event fired , meaning when that happens (i.e when the event fires , when Activated) the initial text would be displayed " ", which is most likely what your text was initially (nothing).
Index the text after Activated so you get the latest text.
If you type stuff inside the textbox, it will be used directly and printed immediately after the SubmitButton is Activated.
local TextBox = script:FindFirstAncestor("ScreenGui").TextBox
script.Parent.MouseButton1Click:Connect(function()
local text = tostring(TextBox.Text)
print(text)
end)