help
01 | local bacmodule = require(script.BACModule) |
02 | local runnerfunctions = { } |
03 | function runnerfunctions.findComponents(cmd) |
04 | local words = { } |
05 |
06 | for word in string.gmatch(cmd, '%S+' ) do |
07 | table.insert(words, word) |
08 | end |
09 |
10 | for _,v in pairs (game.Players:GetPlayers()) do |
11 | if v.Name:lower():match(words [ 2 ] :lower()) then |
12 | triggercommand(words [ 1 ] ,v) |
13 | end |
14 | end |
15 | end |
14:04:01.864 - ServerScriptService.ServerChat.Extensions.BasicAdminCommands:6: bad argument #1 to 'gmatch' (string expected, got table)
heres the other script
1 | if msg:sub( 1 , 1 ) = = ":" and script.Extensions:FindFirstChild( "BasicAdminCommands" ) then |
2 | msg = msg:sub( 2 ) |
3 |
4 | local bac = require(script.Extensions.BasicAdminCommands) |
5 |
6 | bac:findComponents(msg) |
7 | end |
Simply put, it's because you are using obj:method()
notation instead of obj.func()
.
When you call a member function using a colon :
, Lua implicitely passes the object the function is called on as first argument. obj:method(...)
is therefore equivalent to obj.method(obj, ...)
.
Your cmd
parameter receives the value of bac
, and your string argument would be assigned to the second parameter of the function. However since there is no second parameter to receive it, it is simply discarded.
Your module table is clearly not intended to be used as an object; you only use it as a container for functions. When this case, you want to use the period .
to access its member functions instead.