How to make more arguments in admin command

I am creating an admin command system, everything works

game.Players.PlayerAdded:Connect(function(plr)
	plr.Chatted:Connect(function(msg)
		if msg:sub(1,5):lower() == "/kick" then
			local player = msg:sub(7,#msg)
			if game.Players:FindFirstChild(player) then
				game.Players:FindFirstChild(player):Kick("You are gone now")
			end
		end
	end)
end)

but the problem is i want to add more args like “reason” but i cant do that since i have to do #msg in the plr arg, how can i achieve this

also, i refuse to use string.split because its inefficient for admin commands

1 Like

i think it is the only option
or

local str = 'A B':split(' ')

did not test it
i can give more tomorrow

if i do SPLIT

then this will happen

the reason i want:
“You are banned, Haha!”
the reason that pops up
“You”

because it will keep splitting, thats why i refuse it

Or you can put the result of the .split in a table, then just remove the first and second indexes (the command and the player parameter) and then you will have the ban message, which you can join to a string with table.join(" ").
(EDIT): A while ago, I made a module for a command-line project I was working on, and just made a big dictionary with every key being the command base name and the value being another table with command information such as parameters and the function to execute. All worked with string.split, very easy to do.

is there a way to do that with string.sub or any other strings?

I don’t see the need for it, since string.split will accurately split up a string into a table and you can then determine what to do with it. (edit i mixed up .find and .sub) no you cant use .sub since parameters can be different lengths.

last question, is there a string function that can cut words until the given letter or word? , or atleast a way to do it even if it contains string.split

It is better to simply match everything that isn’t a whitespace:

local function split(s)
    local t = {};

    for word in string.gmatch(s, "%S+") do
        t[#t+1] = word;
    end

    return t;
end

im confused in this script, can you explain it?

lol again with string.split, just for loop the table it returns until you hit the thing you want, then break out of the loop and you have your values if you put them all in a table.

fine ill try string.split, ill return with results, also can you like do this:
image

By using the magic of string patterns, we can match a stream of characters until a whitespace. We do this repeatedly by using the gmatch iterator.

%s in string patterns represent whitespace characters.
%S in string patterns represent any character except whitespaces.

%S or %s alone will only a match a single character. We use the plus sign (a class modifier) so we can obtain a stream of characters.

what i need is the string pattern thing to go to the 2nd whitespace and get all of the words next to it, is that possible?

this is not what i explained, just remove the indexing [2][3][4] and remove index 1 and 2, then you have the ban message

ok then, ill try thatttttttt 30 ch ars

can you tell me how to do that? im kinda confused because ill have to go to a sufficient code to do it

trying not to spoonfeed so think of this as an example:

local prefix = "/"
local message = "/kick player1 You have been kicked!"

local split_result = string.split(message," ") -- split message every space
local KICK_ARGUMENT_MINIMUM = 3 -- must be (x) or more arguments to succeed
if #split_result < KICK_ARGUMENT_MINIMUM then error("Must be at least 3 arguments") end
if split_result[1] == prefix.."kick" then
    local plr = split_result[2]
    table.remove(split_result,1)
    table.remove(split_result,2)
    local kick_msg = table.concat(split_result, " ") --> You have been kicked!
end

1 Like

Wow, looks way simpler and better than string.sub

It is in my opinion, here is an API ref link to help you understand it better so you can incorporate it into your own code: string | Roblox Creator Documentation (just scroll down to string.split)

okay, Ill check that string.split

What is the table.join function couldnt find it in a google search