How to get all arguments in a message without having to put them all in a table

I’m have been wondering how to get the full arguments of a message without having to like put them all down in a table.concat()

Here’s what I’m having to do to get all the correct arguments from the player:

local change = table.concat({args[1], " ", args[2], " ", args[3], " ", args[4], " ", args[5]})

Is there a way to get args[6] and so on without having to put them all down which would take forever or just keep it with a limited amount of argumentd.

We need some context to understand this. Can you show the code in situ, or explain what data structure you are calling a “message”?

Its apart of a admin system I have and when the player speaks like :kill TaxFraudBruh, “TaxFraudBruh” is one of the arguments in the command. In this case, I’m wanting all of the arguments after :disguise but I don’t know how to do it without having to add them all to the table.

I’m still kind of confused. If you chat “:kill TaxFraudBruh”, the server gets the message as a string. And normally you do something like string.split(message," ") to split the string into the pieces between the spaces. You get a table.

But I don’t know where your ‘args’ table is coming from, the chat system doesn’t send anything in a table like this, and Roblox Lua doesn’t use args in functions with varargs parameters, you have to convert to array with {…} or use select()

This is where args comes from, I’m not sure how much code I have to show but this is where it gets it from.

plr.Chatted:Connect(function(msg, recp)
	
	string.lower(msg)

	local msgString = msg:split(" ") -- table, {":kill","Builderman"}
	local prefixCommand = msgString[1] -- ":kill"
	local cmd = prefixCommand:split(data.prefix) -- {":","kill"}
	local cmdName = cmd[2] -- "kill"
	
	if commands[cmdName] then

		local args = {}

		for i = 2, #msgString, 1 do
			table.insert(args, msgString[i])
		end
		
		
		commands[cmdName](plr, args) -- Fire command function
	end
end)

Why do you split the message into a table and then reconstruct the string, why not just pass the message string if that’s what you need. What am I missing here? You can rebuild the string in a loop, without having to list out args[1], args[2] etc… but why do any of this in the first place?

If you want to get all arguments, you may find table.concat useful.
Here’s an example:

table.concat(Splits, ' ', 1) -- This will return every argument, starting from 1.

More information can be found here.

1 Like

I was using table.concat() for it but I didn’t know it was usable in that way, thanks though as it works :D.

1 Like