Get all arguments past arg[2]

I am making an announcement system and I need to get what an admin says in the message section for it to show up on other players screens. So far I have only figured out how to make arg[3] show up but I also all args after that to show up to. Anyway for this to be possible?

Code:
if string.find(text, “announce”) then
text = string.split(text, “announce”)
text = string.split(text[2], " ")
if text[2] == “1” then
mod.announce1()
elseif text[2] == “2” then
mod.announce2()
elseif text[2] == “3” then
mod.announce3()
elseif text[2] == “4” then
mod.announce4(text[3], name)
end
end

text = string.split(text, 'announce')
table.remove(text, 1)
print(text:concat(' '))

rewrote the code:

if string.find(text, “announce”) then
text = string.split(text, “announce”)
text = string.split(text[2], " ")
if text[2] == “1” then
mod.announce1()
elseif text[2] == “2” then
mod.announce2()
elseif text[2] == “3” then
mod.announce3()
elseif text[2] == “4” then
mod.announce4(text[3], name)
end
end

ServerScriptService.TabletManager:21: invalid argument #1 to ‘remove’ (table expected, got string)

then text is a string but shouldnt it be a table?

local a1, a2, a3 = string.match(text, "(%w+)%s+(%w+)%s+(.+)")

It will help you to learn string patterns.
a1 should say announce, a2 should say 1 or 2 or whatever, and a3 is the rest of it.

Ok I did something wrong, I edited and it should work now

(https://gyazo.com/111c85c302b96b78e5c14644734069a1) - Here is what is should do if I typed “announce 1”, just for anyone confused.

text = text:sub(#'announce ' + 1)
print(text)

Is announce the first word in the message?

well it would print what number I typed, how does this help me get all the other arguments past the number?

It will just get everything except for the "announce "

yes, it goes "announce (number). if it’s announce 4 then it goes “announce 4 message”, and i need to get the whole entire message past “4”

text = 'announce amogus sus' -- only thing i can come up with
text = text:sub(#'announce ' + 1)
print(text) -- amogus sus

You’d like to make a structure of the command?

i.e: :announce (The whole text)?

this is good, but is there anyway to make it so when i type “announce 1 (message)”, it would only only print the “(message)” and not “1 (message)”?

local Test = table.concat(Split, ' ', 3) -- Split = local Split = Input:split(' ')

3 would be the number which tells the function that it’ll get everything after it.

1 Like

I just need all the arguments past the first 2, “announce (number)”. So if I type in “announce 4 hi guys” it would print “hi guys”

Then you could do:

if string.sub(msg, 11) then -- it will show everything after the number if it's a one digit number
-- code
end
text = 'announce 1 amogus sus' -- only thing i can come up with
text = text:split(' ')
local second = text[2]
table.remove(text, 1)
table.remove(text, 2)
text = text:concat(' ') 
print(text) -- amogus sus