help
local bacmodule = require(script.BACModule) local runnerfunctions = {} function runnerfunctions.findComponents(cmd) local words = {} for word in string.gmatch(cmd, '%S+') do table.insert(words, word) end for _,v in pairs(game.Players:GetPlayers()) do if v.Name:lower():match(words[2]:lower()) then triggercommand(words[1],v) end end end function triggercommand(cmd,plr) if cmd:lower() == "kill" then bacmodule:Kill(plr) elseif cmd:lower() == "explode" then bacmodule:Explode(plr) end end return runnerfunctions
14:04:01.864 - ServerScriptService.ServerChat.Extensions.BasicAdminCommands:6: bad argument #1 to 'gmatch' (string expected, got table)
heres the other script
if msg:sub(1,1) == ":" and script.Extensions:FindFirstChild("BasicAdminCommands") then msg = msg:sub(2) local bac = require(script.Extensions.BasicAdminCommands) bac:findComponents(msg) 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.