ChatCommand error

So when I try and make it so, when a admin who wants to kick a player doesn’t enter a reason or playername, it wont make scripterrors. However, its not really working out well…

[lua]local reason = GetPlayers(text[3])
if text = nil then

ply:PrintMessage(HUD_PRINTTALK, 'Error, you did not add a player to kick!')
return end;

if reason = nil then

ply:PrintMessage(HUD_PRINTTALK, 'Error, you must add a reason!')
return end;[/lua]

GetPlayers is the player.GetAll() etc etc, the error im getting with that code is this,

[ERROR] addons/adam-mod/lua/autorun/server/sv_commands.lua:74: ‘then’ expected near ‘=’

  1. unknown - addons/adam-mod/lua/autorun/server/sv_commands.lua:0

==

Did that, now I get this error.

[ERROR] addons/adam-mod/lua/autorun/server/sv_commands.lua:7: attempt to index local ‘name’ (a nil value)

  1. GetPlayers - addons/adam-mod/lua/autorun/server/sv_commands.lua:7
  2. v - addons/adam-mod/lua/autorun/server/sv_commands.lua:75
    3. unknown - lua/includes/modules/hook.lua:84

[lua]
function GetPlayers(name)

	local players = {}
	
	for k, v in pairs(player.GetAll()) do
	
		if(v:GetName():lower():match(name:lower())) then
		
			table.insert(players, v)
		
		end
	
	end
	
	if(table.Count(players) == 0) then
	
		MsgN('[ADMIN] No players found!');
		return false
		
	end
	if(table.Count(players) > 1) then
	
		MsgN('[ADMIN] There are multiable players!');
		return false
	end
	
	return players[1]
	
end[/lua]

that is the GetPlayers function were the error is coming from.

It’s saying name is nil, perhaps you aren’t passing an actual name value to the function

Yes, I know,thats the point, so it returns and ends the function and lets the admin know what they forgot, i.e: I do !kick adam without a reason, it prints, “Please add a reason.” and ends the function so it doesn’t create script errors like it normally does when you leave out a arg.

Can we please see the entire command code instead of snippets? Text should never be nil if this is in a hook that executes on PlayerSay. If you want it to return nil if the name is nil, then do this at the start of GetPlayers:



if not name then ply:ChatPrint('Invalid Name.') return end


This worked, thanks.

Also sorry for the small bump, internet was out for a few days, so i didn’t get a chance to reply. ^^