Get textbox input

I need am trying to make a script execution GUI where you can paste/type a script into a text box and click an execute button to execute it, but when I execute it it doesn’t print the text I put in, but instead prints the text that was in it originally

Here’s the code

local ScrTxt = script.Parent.Parent.ScriptBox.Text
local Button = script.Parent

Button.MouseButton1Click:Connect(function()
	print(ScrTxt)
end)

and the path if anyone needs it
image

(I am not good with guis at all)

are you trying to print out the text of the textbox

I am trying to print it out as a test before I execute the script entered.

also if you say you’re trying to make a script executioner, source of a script can only be fetched exclusively by a plugin

YOURLOCALHERE.FocusLost:Connect(function()

It is because you are printing the text of the textbox of the variable that was saved. (if you don’t change it, the variable will stay the same) So that’s why it will always be the same. You can change it to:

local ScrTxt = script.Parent.Parent.ScriptBox
local Button = script.Parent

Button.MouseButton1Click:Connect(function()
	print(ScrTxt.Text)
end)

Then it will print the text of the textbox that is currently.

Does it have to be in a local script?

Shouldn’t that variable update when called?

image
the code is already like that

Yes, but it will automatically fire once you press enter after typing.

No, the content of the variable is not updated because you do not.

Oh, i’ve been using a regular server script,

If you use a ServerSided script it will go through the Server instead of the Player… That being said, you won’t have to correct things. When doing things related to Player UI it is best to use Local scripts.

Alright, I will try that! Thanks

Text that was typed by a player does not replicate to the server, use a localscript instead.

The way I imagine it the variable is already a basic string, It won’t change if the original source changes.
So you can either make the variable the textbox and print out the text property or you can not make a variable at all and print it

1 Like

That worked! Thank you