I have a script that is trying to send command data from a GUI over to another script to run the command. This script below only happens when the enter/return key is pressed. But the "enterPressed:Connect(get_command)" doesn't want to work because it doesn't know if I'm pressing the enter/return key and always gives me an error. Is there any way that I could describe this better so that the script picks up that that is part of it?
Easier to read Version: The "enterPressed:Connect(get_command)" keeps giving me errors and I don't know what to do about it. It is trying to send data from a GUI over to another script to be used in a command. The other way this worked was with a GUI where it was "enter.MouseButton1Click:Connect(get_command)" which would send it over to the other script and work. I would like to do just that but with a keypress from the user's keyboard.
If I didn't give enough detail please tell me. I did just start to learn how to script about a month ago and most of this script was a tutorial.
CommandBox.FocusLost:Connect(function(enterPressed)
if enterPressed then
script.Parent.Visible = false
enterPressed:Connect(get_command)
end
end)
Full script:
local rs = game:GetService('ReplicatedStorage')
local commandEvent = rs:WaitForChild('CommandEvent')
local frame = script.Parent
local box = frame.CommandBox
--list of valid commands
local actions = {
';kill' , ';freeze' , ';unfreeze' , ';hide' , ';show' , ';speed', ';jump',
';trail', ';goto', ';find', ';kick'
}
local needValue = {
';speed', ';jump'
}
local function valid_command(action)
for _,command in pairs(actions) do
if command == action then
return true
end
end
end
local function valid_player(person)
local player_table = {}
if person == 'me' then
local player = game.Players.LocalPlayer
table.insert(player_table, player)
elseif person == 'all' then
player_table = game.Players:GetChildren()
elseif person == 'others' then
player_table = game.Players:GetChildren()
for _, admin in pairs(game.ReplicatedStorage.Admins:GetChildren()) do
for pos, plr in pairs(game.Players:GetChildren()) do
if admin.Name == plr.Name then
table.remove(player_table, pos)
end
end
end
else
local player = game.Players:FindFirstChild(person)
if player then
table.insert(player_table, player)
else
return false
end
end
return player_table
end
local function valid_value(action, value)
for _,command in pairs(needValue) do
if command == action then
if not value then
return false
end
end
end
return true
end
local function get_command()
local command = {}
for word in string.gmatch(box.Text, "%S+") do
table.insert(command, word)
end
local action = command[1]
local person = command[2]
local value = command[3]
box.Text = ''
if valid_command(action)then
local player_table = valid_player(person)
if player_table then
if valid_value(action, value) then
commandEvent:FireServer(action, player_table, value)
else
box.Text = 'Value Error'
end
else
box.Text = 'where did that player even go? [Invalid Player]'
end
else
box.Text = 'hang on i have the list somewhere [Invalid Command]'
end
end
CommandBox.FocusLost:Connect(function(enterPressed)
if enterPressed then
script.Parent.Visible = false
enterPressed:Connect(get_command)
end
end)

2 comments
For got to add that I am sending the text data from a textbox to the other script.
Another thing I forgot to add is the (get_command) is a boolean. I have no idea on what that is.