Hello, I recently got some code and I wanted someone to explain it in detail about it.
local Reason = string.sub(string.split(Command, '(')[2], 1, -2)
I would also like to know, if I do “:kick DeveloperCoolBoi (Being bad)” I don’t have to put the parentheses. How would I do that?
Goals: Explain the code AND understanding for the kick reason not to be in parentheses.
-- Example Script
-- Shouldn't be used 1:1 in production as this isn't scalable
-- table documentation: https://create.roblox.com/docs/reference/engine/libraries/table#concat
local command = ":kick" -- Name of the command
local message = ":kick HugeCoolboy2007 noob" -- Full command message
local split = message:split(" ") -- Splits the message into different section based on spaces inbetween each word
-- split is now a table: {[1] = ":kick", [2] = "HugeCoolboy2007", [3] = "noob"}
local cmd = split[1] -- This gets the first word from the split string (":kick")
if cmd == command then -- This check if the first word matches the command
table.remove(split, 1) -- This removes the first table element (":kick"). This shifts all the keys over to fill the gap
local target = split[1] -- Since ":kick" was removed, the new first element is "HugeCoolboy2007", who is the target
local reason = table.concat(split, " ", 2) -- This takes the rest of the table and turns it into a string (starting from the second element)
print(target, reason) -- Prints "HugeCoolboy2007" and "noob"
end