Script Registering textbox as empty

Hello! So I’m trying to make a Moderation Panel where I can Kick, Ban, Temp Ban, and do announcements. I’m currently working on the Kick option but when I press the button it says the text box is empty.

Pictures:

Clearly not empty

image

Code:


local Main = script.Parent

local Player = game.Players.LocalPlayer

--// INFO \\--

local BanDuration = Main.BanDuration.Text
local Reason = Main.Kick_BanReason.Text
local Message = Main.Message.Text
local PlayerName = Main.PlayerName.Text

--// MODERATION \\--

local RemotesFolder = game:GetService("ReplicatedStorage").Remotes.ModPannel

local ModButtons = Main.ModButtons

ModButtons.Kick.MouseButton1Click:Connect(function()
	
	--print("Test")
	
	print(Reason, PlayerName)
	
	RemotesFolder.Kick:FireServer(Player.UserId, Reason, PlayerName)
	
end)

Sorry for the trouble and thanks for the help!

1 Like

That is because “Reason” variable is never updated after the script runs. The fix is simple, just put the reason variable inside of the click function,

ModButtons.Kick.MouseButton1Click:Connect(function()
	
	--print("Test")
	local Reason = Main.Kick_BanReason.Text
	print(Reason, PlayerName)
	
	RemotesFolder.Kick:FireServer(Player.UserId, Reason, PlayerName)
	
end)
2 Likes

When you declare the “Reason” variable, you are declaring how it is when the game starts. When the game starts, the text is empty. A fix would be to declare the reason as “Main.Kick_BanReason”.

Then when you print the reason:

print(Reason.Text, PlayerName)

print the “reason.text”, which will print what is in the text box at the time of clicking the kick button.

1 Like

I did something similar to that:

ModButtons.Kick.MouseButton1Click:Connect(function()
	
	--print("Test")
	Reason = Main.Kick_BanReason.Text
	PlayerName = Main.PlayerName.Text
	print(Reason, PlayerName)
	
	RemotesFolder.Kick:FireServer(Player.UserId, Reason, PlayerName)
	
end)

I did this instead because I will need to use those Textboxes for the Ban, Temp ban and Local Announce as well.

Thank you very much!!

2 Likes