bad argument #1 to string_gmatch

Why is it doing it?

this is what i get:


error in string.lua

[ERROR] lua/includes/extensions/string.lua:91: bad argument #1 to 'string_gmatch' (string excepted, got userdata)
1. string_gmatch - [C]:-1
2. Explode - lua/includes/extensions/string.lua
3. fn - lua/cwarn.lua:35
4. unknown - addons/ulib/lua/ulib/shared/hook:179

line 35 of cwarn.lua:
if (text == "!admincommands") then

i am trying to create chat commands with PlayerSay hooks.

Full Code where error appears:


function commands( text, ply )
if ( text == "!admincommands" ) then
PrintMessage(3, "!report  name  reason
!warning  name  reason
!rweapons  name  reason
!giveweapon  weapon_name  player")
end
end

Post more code

I believe this is what your looking for. Well with string.lower


hook.Add( "PlayerSay", "Killurself", function( ply, text, public )
	text = string.lower( text ) -- Make the chat message entirely lowercase
	if ( text == "!kill" ) then
		ply:Kill()
		return ""
	end
end )


Args are in the wrong order;
replace with the following:


function commands( ply, text, is_team_chat )
    if ( text:lower() == "!admincommands" ) then -- lowercase the supplied text and check if it matches the expected chat command(s).
        PrintMessage(3, "!report  name  reason
!warning  name  reason
!rweapons  name  reason
!giveweapon  weapon_name  player")
        -- return "" // removing the -- at the start of this line, will make it so that the supplied text(command) is not printed to chat, when sent the player executes the command.
    end
end

Thanks faedro, it works perfectly now.