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

How can I get text from a text box?

Asked by 5 years ago
Edited 5 years ago

I have a text box that I want people to enter their text in. After they press enter, it is supposed to press enter and fire a remote event. The text should then be printed into the output, but it prints nil instead of what the player entered. How would I fix this? By the way: This is on a surface GUI. Here is my button script:

script.Parent.MouseButton1Click:Connect(function()
    local text = script.Parent.Parent.TextBox.Text

    game.Workspace.Events.Text:FireServer(text)
end)

Here is my print script:

script.Text.OnServerEvent:connect(function(plr, text)
    print(text.Value)
    end)
0
Use RemoteEvents in ReplicatedStorage, scripts for RemoteEvents in Workpsace or ServerScriptService. yHasteeD 1819 — 5y
0
Also don't forget to use FilterStringAsync either, it won't error in testing mode but if you don't filter it, Roblox will disable the place till you fix it. It basically filters the text to make sure it's safe for users to see/read. Here is a link to the wiki about it, https://developer.roblox.com/articles/Text-and-Chat-Filtering Stephenthefox 94 — 5y

2 answers

Log in to vote
0
Answered by
Imperialy 149
5 years ago
Edited 5 years ago

localscript

script.Parent.MouseButton1Click:Connect(function()
    local text = script.Parent.Parent.TextBox.Text

    game.Workspace.Events.Text:FireServer(text) -- fire the textbox's Text in the 2nd arg
end)

serverscript

script.Text.OnServerEvent:Connect(function(plr, text) -- use Connect not connect
    print(text) -- prints the text
end)

text doesn't have a value

0
I tried this, but it printed nothing then. CaptainD_veloper 290 — 5y
0
nvm CaptainD_veloper 290 — 5y
Ad
Log in to vote
0
Answered by
pidgey 548 Moderation Voter
5 years ago
Edited 5 years ago

I suggest you rubber duck your code. Say it out loud, line by line. You're listening to a different event than what you're firing.

0
Oh wait sorry CaptainD_veloper 290 — 5y
0
Put this in a comment, not in answer area. yHasteeD 1819 — 5y

Answer this question