Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

4 comments

0

Your script tells you that on line 6 it expects a string not a table.

0

there i'snt a table there

0

Looks like there is. Scripts aren't stupid, they just do what you tell them to do.

0

then where is it

1 answer

✓ Accepted answer

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.

1 comment

0

OOOHHH I'm so stupid xD

This discussion is preserved as it was. New answers, comments, and votes are closed.