Hello, I’m trying to make a custom admin GUI. But the text value of the textbox returns to a nil value. I found this out by printing the second argument.
Local script:
local commandFrame = script.Parent.CommandFrame
local commandBox = commandFrame.MainBox
local UserInputService = game:GetService("UserInputService")
local prefix = "/"
local player = game.Players.LocalPlayer
commandFrame:TweenSize(UDim2.new(1,0,0,0),Enum.EasingDirection.InOut,Enum.EasingStyle.Quad,.5)
local function inputBegan(input,typing)
if input.KeyCode == Enum.KeyCode.Semicolon then
commandFrame:TweenSize(UDim2.new(1,0,0.1,0),Enum.EasingDirection.InOut,Enum.EasingStyle.Quad,.5)
commandBox:CaptureFocus()
end
end
local function focusLost(enterPressed)
if enterPressed then
local lowerText = commandBox.Text:lower()
local text = lowerText:split(" ")
local command = text[1]
local splitCommand = command:split(prefix)
local commandName = splitCommand[2]
if commandName then
local arguments = {}
for i=2,#text,1 do
table.insert(arguments,text[i])
end
game.ReplicatedStorage.FireCommand:FireServer(commandName,arguments)
end
commandFrame:TweenSize(UDim2.new(1,0,0,0),Enum.EasingDirection.InOut,Enum.EasingStyle.Quad,.5)
end
end
UserInputService.InputBegan:Connect(inputBegan)
commandBox.FocusLost:Connect(focusLost)
Server script:
local commands = {}
local function findPlayer(target)
for i,v in pairs(game.Players:GetPlayers()) do
if v.Name:lower():sub(1,#target) == target:lower() then
return v
end
end
return nil
end
commands.kill = function(player,arguments)
local target = arguments[2]
if target then
local plrTarget = findPlayer(target)
if plrTarget then
plrTarget.Character.Humanoid.Health = 0
end
end
end
game.ReplicatedStorage.FireCommand.OnServerEvent:Connect(function(player,commandName,arguments)
print(player,commandName,arguments[2])
if commands[commandName] then
commands[commandName](player,arguments)
end
end)
Arguments[2] prints as nil and the command doesn’t run.