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

I am trying to use the text of a text box in a server script, it always doesn't detect the text?

Asked by 5 years ago
Edited 5 years ago

here is the script

local box1 = script.Parent.Parent.TextBox

script.Parent.MouseButton1Click:Connect(function()
    print(box1.Text)
end)

0
is this a screen gui or a surface gui? UnforgivenJr3087 26 — 5y
0
Screen YahiaElramal_77 26 — 5y

2 answers

Log in to vote
0
Answered by
2ndwann 131
5 years ago
Edited 5 years ago

Well, I think the problem here is that the variable does not really update with the GUI. So, to make it update, try using a .Changed event to detect if the text has been updated or not. And, I recommend making a separate variable of the "Text" property rather than the whole thing itself. (it makes it easier)

local box = script.Parent.Parent.TextBox -- variable for the box
local boxText = box.Text -- make a separate variable for the text

box.Changed:Connect(function() boxText = box.Text end) -- update the boxText variable each time the text changes

script.Parent.MouseButton1Click:Connect(function()
    print(boxText)
end)

I hope this helps!

Ad
Log in to vote
0
Answered by 5 years ago

You locate the text if it is " ". You just have to locate the text in the function!

local box1

script.Parent.MouseButton1Click:Connect(function()
    box1 = script.Parent.Parent.TextBox
    print(box1.Text)
end)
0
And... Dont use numbers for variables :D RedstonecraftHD 25 — 5y

Answer this question