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
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.
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
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.
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
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)