Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Why does my script think my string is a table and can somebody help fix it?

Asked by 6 years ago
Edited 6 years ago

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
0
Your script tells you that on line 6 it expects a string not a table. AltNature 169 — 6y
0
there i'snt a table there Gavinboy3000 98 — 6y
0
Looks like there is. Scripts aren't stupid, they just do what you tell them to do. superalp1111 662 — 6y
0
then where is it Gavinboy3000 98 — 6y

1 answer

Log in to vote
1
Answered by
Link150 1355 Badge of Merit Moderation Voter
6 years ago
Edited 6 years ago

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.

0
OOOHHH I'm so stupid xD Gavinboy3000 98 — 6y
Ad

Answer this question