How to get Text from a TextBox

  1. This may seem like a simple question but for some reason, I could not manage to find my way in this one. How do you get text from a TextBox?

  2. there is no error but when I try it either says nil or either just does not work.

  3. I have tried looking around in the dev forum but nothing seems to help me.

local textBox = script.Parent.Frame.Name	
local addButton = script.Parent.Frame.TextButton



textBox.FocusLost:Connect(function()
	print(textBox.Text)
end)
4 Likes

Maybe the event is not triggering. I have no idea how that event is triggered, give us some hints.

1 Like

Is the script a Localscript, and are you sure the function is firing AFTER the user has put input into the box? And change it from Name, to something else… remember, name is already used as a property type.

4 Likes

the event is not triggered indeed. But even if it is the text is nil. The event gives this error " Players.Dev_Simphony.PlayerGui.ScreenGui.LocalScript:6: attempt to index nil with ‘Connect’ "

Yes! Name was the cause of the Event not triggering. Thanks for pointing this out mate!! Alright! everything is now working. I was just stupid and named my frame Name. Thanks again

1 Like

It’s likely you issue is what @sloss2003, Roblox prioritises properties over Instance names. So if you named an instance Name, it will assume you’re getting the property Name and not an Instance called Name.

To give a more practical example, let’s say you have a thing in workspace called Part, and it has a child called Name and you want the Color of it, you’d do

workspace.Part.Name.Color

But it would error cause the game would get the name of the Part, not a child called Name. You can simply rename the Instance or use FindFirstChild

workspace.Part:FindFirstChild("Name").Color

Which would also fix it

Very late yes but wanted to give some extra info

2 Likes

Thank you so much!! its not the first time your here to correct my mistakes :rofl: . Thanks for coming and helping me out!!

1 Like

Its Because you are using it on a frame. local textBox = script.Parent.Frame.Name
Where there is not any Text in a Frame.

Instead try to get the TextButton Example
local TextButton = script.Parent.Frame.TextButton

1 Like

It’s not an issue with the frame, as stated earlier, it’s because @OP named the Textbox Name, which made the game assume he was trying to get the name of the Frame instead of the textbox, the fix was just to rename the textbox

2 Likes