Returning Multiple Strings

I am expanding on my custom admin, my aim is to add command suggestions so when you begin typing it returns commands relevant to the textbox text. However I can only return 1 string when I want Multiple. I am in need of a solution that provides what code I should use to solve this issue.

Example: https://gyazo.com/40d720c03c51e56f5fe46a0eaaa6bfa8

local Commands = {"track","kick","ban","view","tban"}

local function findCommand(stringg)
    for _, v in pairs(Commands) do
         if stringg:lower() == (v:lower()):sub(1, #stringg) then
               return v
         end
    end
end


game.ReplicatedStorage.RemoteFunction.OnServerInvoke = function(plr,text)
		local String = findCommand(text)
		return String
end

Local Script:
local a = game.ReplicatedStorage.RemoteFunction:InvokeServer(text.Text)
if not script.Parent.List:FindFirstChild(a) then
Clean()
local Template = script.Template:Clone()
Template.Text = a
Template.Parent = script.Parent.List
Template.Name = “Template”
end

Once you return something, the last thing being returned will be the one you see. What you should do is send a table.

local function findCommand(stringg)
    local CommandsTable = {}
    for _, v in pairs(Commands) do
         if stringg:lower() == (v:lower()):sub(1, #stringg) then
               table.insert(CommandsTable, v)
         end
    end
   return CommandsTable
end

How would I stop it returning all the strings with a blank textbox?

A simple if statement.

local function findCommand(stringg)
    local CommandsTable = {}
    for _, v in pairs(Commands) do
         if stringg:lower() == (v:lower()):sub(1, #stringg) then
               table.insert(CommandsTable, v)
         end
    end
   if stringg ~= "" then
      return CommandsTable
   end
end
1 Like