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!