Help with admin arguments/strings

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 Like

Considering that firesize is a string, you should convert it to a number.

new.Size = tonumber(firesize)
1 Like

I did that, but it still doesn’t work.

1 Like

Nope. It’s still not working. Any other suggestions?

1 Like

Nope. It still doesn’t work. If I use just :fire ChasingNachos, it doesn’t work then either.

Possibly to do with the fact that :len should be .len? If not, I would suggest debugging to see what the values of the variables are, etc to find the issue.

Nope. It still doesn’t work. Anything else?

I have no other suggestions without seeing the entire script or the output.

Entire Script:

local Owners = {"", ""}
local Super_Admins = {"", ""}
local Administrators = {"", ""}
local Moderators = {"", ""}
local Banlist = {"", ""}
local Prefix = ":"
	
game.Players.PlayerAdded:Connect(function(p)
	local folder = Instance.new("Folder", p)
	folder.Name = "AdminLevel"
	local value = Instance.new("StringValue", folder)
	value.Name = "AdminValue"
	value.Value = "Non Admin"
	for i,v in pairs(Moderators) do
		if p.Name == v then
			p.AdminLevel.AdminValue.Value = "Moderator"
		end
	end
	for i,v in pairs(Administrators) do
		if p.Name == v then
			p.AdminLevel.AdminValue.Value = "Administrator"
		end
	end
	for i,v in pairs(Super_Admins) do
		if p.Name == v then
			p.AdminLevel.AdminValue = "Super Administrator"
		end
	end
	for i,v in pairs(Owners) do
		if p.Name == v then
			p.AdminLevel.AdminValue.Value = "Owner"
		end
	end
	if p.UserId == game.CreatorId then
		p.AdminLevel.AdminValue.Value = "Game Creator"
	end
	for i,v in pairs(Banlist) do
		if p.Name == v then
			p:Kick("You have been banned from this game.")
		end
	end
	if p.AdminLevel.AdminValue.Value == "Moderator" or p.AdminLevel.AdminValue.Value == "Administrator" or p.AdminLevel.AdminValue.Value == "Super Administrator" or p.AdminLevel.AdminValue.Value == "Owner" or p.AdminLevel.AdminValue.Value == "Game Creator" then
		p.Chatted:Connect(function(msg)
			local kickcommand = Prefix.."kick "
			local firecommand = Prefix.."fire "
			if msg:sub(1, kickcommand:len()):lower() == kickcommand:lower() then
				local name = msg:sub(kickcommand:len() + 1)
				local kickedplayer = game.Players:FindFirstChild(name)
				if kickedplayer then
					kickedplayer:Kick("You have been kicked from this game by "..p.Name..".")
				else
					print("Player not in game!")
				end
			end
			if msg:sub(2, firecommand:len()):lower() == firecommand:lower() then
				local name = msg:sub(firecommand:len() + 1)
				local firesize = msg:sub(firecommand:len() + name: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 = tonumber(firesize)
				else
					print("Player not in game!")
				end
			end
		end)
	end
end)

There is nothing in the output.

I would recommend taking this in steps. First of all, check if the message is a command, then remove the prefix.

local IsCommand = string.match(msg, "^" ..Settings.Prefix)
if IsCommand then
   msg = string.gsub(msg,IsCommand,"",1) -- Removed prefix
end

Once you have determined it is indeed a command, split it into different words:

local Arguments = {}

for Argument in string.gmatch(Message,"[^%s]+") do
    table.insert(Arguments,Argument)
end

^^ this goes in the if IsCommand then statement

Then, you can get each individual word by doing this:

local Word = Arguments[2]

If you have any questions, please ask!

1 Like

How would I implement that into my full code (which is shown in the reply above)?

local IsCommand = string.match(msg, "^" ..Settings.Prefix)
local Arguments = {}
if IsCommand then
   msg = string.gsub(msg,IsCommand,"",1) -- Removed prefix

   for Argument in string.gmatch(Message,"[^%s]+") do
       table.insert(Arguments,Argument)
   end
end

if Arguments[1] == "kick" then
	local name = Arguments[2]
	local kickedplayer = game.Players:FindFirstChild(name)
	if kickedplayer then
		kickedplayer:Kick("You have been kicked from this game by "..p.Name..".")
	else
		print("Player not in game!")
	end
end

It would look something like that.

Have you tried this?
And also, for debugging, it would look something like this:

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)
  print(firesize, name) -- check if the values are correct
  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

I checked the output, and nothing was printed. Not sure why.

It wouldn’t work. len is a method of the string, so it has no idea what string you’re trying to get the length of if you don’t use colon syntax. Also, you should probably be doing #str rather than str:len(), but this is mostly a stylistic choice.

The error would look something like this:

input:1: bad argument #1 to 'len' (string expected, got no value)
3 Likes

As posatta said, use #variable instead of string.len method. I’ve found it much more convenient.

It would look like this:

if msg:sub(2, #kickcommand):lower() == kickcommand then

you also dont need to :lower() the kickcommand variable because it already is in lower case.

All of this applies the same to your firecommand variable as well.

I also suggest removing the prefix out of the message which makes things easier when checking which command was being used so you dont have to sub() it every time. Example:

local msg = ":kick/Player1"
local cmd = msg:sub(2) -- removes prefix, also allows prefix to be anything : ; / ! etc...
if cmd:sub(1,4):lower() == "kick" then
    local plr = game.Players:FindFirstChild(cmd:sub(6))
    if plr then plr:Kick("kick message") end
elseif cmd:lower() == "kickall" then
    for k,v in pairs(game.Players:GetPlayers()) do
        v:Kick("everyone got kicked")
   end
end