I am making an admin system, and I would like to know how I can have two arguments (for this challenge, I am making a fire command, which arguments will be target and size). Target works, but size does not.
if msg:sub(2, firecommand:len()):lower() == firecommand:lower() then local name = msg:sub(firecommand:len() + 1) local firesize = msg:sub(firecommand:len() + 2) local fireplayer = game.Players:FindFirstChild(name) if fireplayer then local new = Instance.new("Fire") new.Name = "AdminControlledFire" new.Parent = fireplayer.Character.HumanoidRootPart new.Size = firesize else print("Player not in game!") end
For this you can use the string.gmatch
function. . The first argument of the function is the string to be processed and the second argument is the so called 'Pattern'. The pattern determines how the string will be separated, and in your case we want the string to be separated by spaces.
Here's an example:
for arg in string.gmatch("argument1 argument2 argument3","%S+") do print(arg) end
Output:
argument1
argument2
argument3
As you might have noticed the pattern is set to '%S+', lua doesn't accept an input of " " (literally a space); so you must use this method instead.
If we want to store the variables we can do this:
args = {} for arg in string.gmatch("argument1 argument2 argument3","%S+") do table.insert(args,#args + 1,arg) end print(args[2])
Output:
argument2