Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How do I make it so an admin command can have two arguments?

Asked by 4 years ago

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

1 answer

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

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

0
you can now use string.split(string, " ") too Luka_Gaming07 534 — 4y
Ad

Answer this question