Can't get text from TextBoxes

I am making a script that posts to Trello with the information players fill out using text boxes.

local api = require(game.ServerScriptService.TrelloAPI)
local plr = game.Players:GetPlayers()


	script.Parent.MouseButton1Click:Connect(function()
api:AddCard(""..plr[1].Name.."","Reason: "..script.Parent.Parent.Parent.Parent.back.link.reason.TextBox.Text.." Duration: "..script.Parent.Parent.Parent.Parent.back.link.duration.TextBox.Text.."","5e8e95d41f2f45674ceaa92f")
wait(10)
plr[1]:Kick("You are now on-leave.")
end)

Everything works except it’s not posting the text in the TextBoxes:

Screen Shot 2020-04-10 at 11.02.47 PM

Any idea why this is happening?

There is no errors in the console.

It works when I put the text in prior to joining the game.

1 Like

Could it be a problem with your modulescript?

1 Like

Don’t think so because when I manually insert the text into the textbook prior to joining the game it works.

So you mean if you manually typed the text into the text box and click the button, it would run normally?

1 Like

Exactly. It would put what I typed into the textbook in the card description.

Perhaps try to get the textbox from PlayerGui?

The script is in the PlayerGUI and is requiring the module from ServerScriptService.

Still does not work :cry: Any other suggestions?

Is this a server script and are you firing remotes to transfer input from the local textbox to the server?

Nope. The server script is grabbing the Text directly from the TextBox and posting it to Trello.

You’ll need to fire a remote from the textbox input to the server instead.

3 Likes

I did this. No errors but it’s not posting to trello now.


game.ReplicatedStorage.text.OnServerEvent:Connect(function(reason, duration)
api:AddCard(""..plr[1].Name.."","Reason: "..reason.." Duration: "..duration.."","5e8e95d41f2f45674ceaa92f")
wait(10)
plr[1]:Kick("You are now on-leave.")
end)

Where do you fire the event? and the first parameter in a remote event is the player
function(player,reason, duration)

It’s in a TextButton:

script.Parent.MouseButton1Click:Connect(function()
	game.ReplicatedStorage.text:FireAllClients(script.Parent.Parent.Parent.Parent.Parent.Parent.back.link.reason.TextBox.Text, script.Parent.Parent.Parent.Parent.Parent.Parent.back.link.duration.TextBox.Text)
end)

I don’t understand why I need to add the player as a parameter since I already have the player defined.

When you fire the remote, it automatically passes in a player parameter as the first.

On the client (which is where that script should be), you should use FireServer not FireAllClients. Also how do you have the player defined on the server? from the player added event?

local plr = game.Players:GetPlayers()

plr[1] - since it’s a one player game.

1 Like

I’m going to backtrack a bit here and start back at the top.

The one thing I want to know is how you got this to work in the first place if you’re using a LocalScript, because children of ServerScriptService do not replicate to the client. The only other case I can think of is that you’re using a server script in your Gui.

If you’re using a server script, please change; you aren’t supposed to be using scripts in Guis, only LocalScripts. You will then need a remote to communicate with the server. All Guis should always only be controlled by the client. The only time a server should ever interact with Guis is to replicate them.

The reason why your script doesn’t pick up the text in TextBoxes is because TextBox input is client-sided. When the client types in a text box, it updates the Text property. The client cannot authoritatively propagate any changes to properties bar a very select few, so the server never sees what the client types. This is why your fields appear blank.

In order to fix this, you will need a RemoteEvent, one script and one LocalScript. The script should be in ServerScriptService and the LocalScript in the same place wherever your current script is. The remote will be in ReplicatedStorage so both the server and client can see and access it. You will then communicate accordingly through this remote.

I can walk you through converting your system to use the proper strategies, but anything further (security, additions, debugging and the like) are your own to handle.

From the LocalScript, it will use the RemoteEvent to submit an action request to the server:

* Please, in the future, put LocalScripts directly under the Gui and not inside a button. It’ll make accessing objects far easier and you don’t have to dig around to be able to find the script.


local remote = game:GetService("ReplicatedStorage").RecordInactivity

-- Keeping the above note in mind, added variables to make it easier to read
local reasonBox = script.Parent.Parent.Parent.Parent.back.link.reason.TextBox
local durationBox = script.Parent.Parent.Parent.Parent.back.link.duration.TextBox

script.Parent.MouseButton1Click:Connect(function ()
    -- Inform the server of the reason and duration of the leave
    remote:FireServer(reasonBox.Text, durationBox.Text)
end)

From the script, we will hook a function to the remote to determine when the client has sent data and how we should proceed:

local api = require(game:GetService("ServerScriptService").TrelloAPI)
local remote = game:GetService("ReplicatedStorage").RecordInactivity

-- Remotes will receive the requesting player automatically as the first
-- argument. See the Developer Hub for more information.
local function handleInactivityRequest(player, reason, duration)
    -- You can use the raw string, the player's name, here. No concatenation
    -- or type coercion is required because it's already a string.
    local cardName = player.Name
    -- Easier to read when they're variables. By the way, that \n part starts
    -- a new line, so you can read the data better!
    local cardText = "Reason: " .. reason .. "\nDuration: " .. duration

    api:AddCard(cardName, cardText, "5e8e95d41f2f45674ceaa92f")
    -- This'll run after AddCard succeeds, so we can remove them right away
    player:Kick("You are now on leave.")
end

-- I do this because I find it easier to read and if I need functions later. You
-- can also connect directly, doesn't matter.
remote.OnServerEvent:Connect(handleInactivityRequest)

PS: You’ll want to refresh that end hash if that’s a token or security key, by the way. When posting topics on public categories, remember to redact any sensitive information (API keys especially) so you can protect your program secrets!

7 Likes

You are an absolute lifesaver. Thank you for the great advice. I don’t script much unless it’s for tweening GUI’s. This solved all my problems.

Also, that number at the end is just a listid and can’t be posted to without my token which is kept secret. Thank you for your concern.

Cheers.

2 Likes